-
Create a class
FileOut
that does some file output. Your program should ask the user to enter real numbers (double
), writing each one to a filenumbers.txt
. The user should indicate the end of their input by entering a non-number.For example, when the program is run it might look like this:
Enter some numbers:
1.23
4.56
7.89
0.12
abc
Done.The easiest way to do this is to use a
Scanner
object and.nextDouble()
, using.hasNextDouble()
to check that the next input is a number. The easiest way to do the output is with aPrintWriter
.The file produced from the above run should be:
1.23
4.56
7.89
0.12 -
Create a class
FileIn
that does some file input. Your program should ask the user to enter a filename. It should open the file and count the number of lines and characters in the file.For example, we could run the program on the file from the previous question:
Enter the filename:
numbers.txt
Lines: 4
Characters: 20
Use a
Scanner
object to wrap the file input stream. In a loop, read lines from the file with.nextLine()
. For each line, add one to the number of lines, and the length of the string to the number of characters.Note that the program counts the newline characters at the end of lines as well as the visible characters. The
.nextLine()
method doesn't include these in the string: you'll have to add one for each line to compensate. -
Create a text file named
time.txt
. In it, indicate how long it took you to complete this lab exercise.
When you're done, create a ZIP file containing all of the files you created for this lab and submit it with the submission server.