Question:
Java Program - Need help? (Re post)?
Sweetillusions
2012-12-23 10:11:13 UTC
Hi, I am trying to compile a Java program. The Java program should be set to read an external Text file which has long set of random number.
So, the program should have the ability to read the text file determine the highest number and the lowest number on that text file. The results should be visible on Console ( I am using Eclipse).
So say these are the random number -

109.0 109.0 110.0 110.0 110.0 109.0 105.0 104.0 103.0 105.0 108.0 111.0 112.0 112.0 112.0 110.0 109.0 106.0 103.0 100.0 98.0 95.0 92.0 90.0 88.0 94.0 103.0 109.0 111.0 110.0 110.0 110.0 110.0 110.0 110.0 110.0 110.0 109.0 106.0 103.0 100.0 98.0 95.0 93.0 91.0 89.0 88.0 87.0 86.0 86.0 87.0 88.0 89.0 90.0 90.0 90.0 90.0 90.0 90.0 90.0 89.0 87.0 87.0 85.0 84.0 84.0 84.0 85.0 87.0 89.0 92.0 96.0 99.0 103.0 106.0 109.0 111.0 112.0 112.0 112.0 111.0 110.0 110.0 109.0 108.0 106.0 105.0 103.0 101.0 99.0 95.0 91.0 89.0 87.0 88.0 89.0 94.0 98.0 99.0 98.0 97.0 94.0 91.0 90.0 89.0 91.0 98.0 102.0 104.0 105.0 104.0 102.0 101.0 99.0 98.0 96.0 93.0 91.0 88.0 85.0 81.0 79.0 77.0 77.0 77.0 77.0 79.0 81.0 83.0 87.0 90.0 93.0 96.0 98.0 102.0 106.0 109.0 111.0 112.0 111.0 111.0 110.0 108.0 106.0 104.0 101.0 99.0

Would appreciate if you could also comment on each code so i know what each line means.

Many many thanks for reading
Four answers:
?
2012-12-23 10:26:11 UTC
I will do some parts for you and leave others blank. You HAVE TO MUST HAVE TO MUST google like crazy and use the JAVA API website. I am a professional developer and took computer science in college. I wrote a lot of Java and was on google and using the Java API site like crazy.

If I write ________ then that is a blank you have to fill in. Sometimes I put a blank in the middle of the word



Here is a newbie way of doing it

Scanner hello = ___ Scanner(new File(numbers.txt));

float max;

float min;

while (hello.hasNext____() ){

Scanner theLine=new ______(hello.nextLine());

while(_______.hasNext()){

_____number=theLine.Next();

float num= Float.parse_____(number);

if(num>max)

_____________

if (num
___________

}

}



I know there is a better way to do this. Using two scanners is not ideal nor professional but the best I could come up with on the top of my head and without using google.

since all of these end in .0 you can change the floats to integers



oops fixed an error, now it should make more sense and compile. Once you fill in the blanks of course.

I STRONGLY suggest you look up the API for the following classes.

String

Float

Integer

Scanner

note that int and Integer are different

float and Float are also different
?
2016-08-08 09:30:53 UTC
Are you in a position to bring together it into a class file? As soon as you will have finished that, enter the command: jar cvf nameOfJarFile.Jar nameOfClassFile.Class if you are unable to collect it into a class file, you then must fix the Java code unless such time as the compiler likes it well adequate to provide you with a class file. Thereafter, making a jar file is inconspicuous. One line command. Displaying us the Java source code is not going to help anyone let you know create a jar file. Assemble it into a class file. The program that creates the jar file does not care what you put into the jar file. Certainly, I've recognized humans to put each the class file and the fashioned Java source into the jar file. That you would be able to put anything you like right into a jar file on the grounds that, at its root, it's just a Zip file with a specified listing constitution that allows it to optionally hold a appear file. I count on the intent nobody answered your query earlier than used to be considering that it didn't make sense. It used to be like asking, "Why does not the manufacturing facility GPS procedure work in my Pinto?" good, they stopped making Pintos lengthy before GPS was once invented. So the question would not make feel. Might be the asker meant to ask, "Why does not the Camry GPS process work after I install it in my Pinto?" that's variety of a ordinary factor to do, however at the least the query makes extra sense.
anonymous
2016-04-28 11:18:39 UTC
Mastering the foundational reading abilities allows your youngster to target on understanding the topic they are reading rather than struggle with understanding what eventually leading to a more rewarding and satisfying examining knowledge and this is in what this program Children Learning Reading from here https://tr.im/CRHnb is based.

Children Learning Reading use methods to greatly help your child read and improve his reading, appreciation, and spelling capacity in the early school years.

Although the Young ones Understanding Reading program is situated about your son or daughter learning the small appears that produce up each word there are several phrases in the English language that only can't be learned this way (rhythm for example). In order to aid one to train your youngster these outstanding words an guide is offered to the most frequent phrases that need to be learned by sight.

This benefit may be specially beneficial in the event that you and your son or daughter are experiencing a specific word. You realize when the word is included in the guide then it's something that can not be discovered applying the Children Learning Reading method.
deonejuan
2012-12-23 11:38:53 UTC
Probably you can't read a file because you can't get the path to the file correctly.



import java.io.File;

import java.io.FileReader;

import java.io.IOException;

import java.util.Scanner;





public class TextFileScanHiLo {





public static void main(String args[]) throws IOException {

/**

* To create a File Object the best constructor is:

* File( directory, filename); both args are String

* also, we can call constants: System.getProperty( ",,,)

* so this is most idiot-proof way I know to get the path.

* your text file should reside with the .class file of this program

*/

File f = new File(

System.getProperty("java.class.path"),

"datanums.txt");



FileReader fin = new FileReader(f);



Scanner src = new Scanner(fin);



// Java has a constant to retrieve the MAX and MIN double

// first we load a var ceiling with MIN

// then we load a var floor with MAX



double floor = Double.MAX_VALUE;

double ceiling = Double.MIN_VALUE;

double d;



while (src.hasNext()) {

if (src.hasNextDouble()) {

d = src.nextDouble();

// then we use methods of Math

// these will compare and return the largest or the smallest

floor = Math.min(floor, d);

ceiling = Math.max( ceiling, d );

}

}

// always close a stream

fin.close();



// This is printf( fmt, args );

// you could use String + var + String and then System.print.out();

System.out.printf("Ceiling number: %.2f and Floor number: %.2f%n", ceiling,floor);

}



}


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...