The user will see something like:
C:\java AddUpFile < largeData.txt Enter a number: Enter a number: Enter a number: Enter a number: Enter a number: Enter a number: .... and so on 100 times Grand Total: 1688
One hundred useless prompts could be irritating.
Programs that read from a file do not need prompts. But when you are first writing the program it is good to include them so you can more easily debug the program. Once the program is debugged, change the line that prints the prompt:
//System.out.println("Enter a number:");
If you need the prompt in again, it is simple to remove the slashes.
It would greatly enhance your development as a world-class programmer to copy this program play with it.
You will need a data file of 100 integers. This is easy to do. In a text editor, enter 10 lines of numbers, something like:
1 2 3 4 5 -1 -2 -3 -4 -5
Now use the copy and paste commands to make 9 duplicates of these
ten lines.
You will have 100 lines of integers which should sum to zero.
Save the file under some convenient name,
such as zeroData.txt
.
Use it with your program.
What will happen if there are fewer integers in the file than the program needs?