a) Write a method to create a text file named numbers.txt that is to contain the whole numbers 101 to 10000 (use a for loop to write the output to the file). Write a second method that will read the data from numbers.txt and display the content to the screen (one value per line of output). Write a third method that can be used to add (sum) all of the numbers from the file and display their total on the screen - do not use an array. Write a program that includes all of the above methods. Your program must allow the user to choose if they want to create the file (first method), read & display the file content (second method), read and calculate the total from the file (third method), or exit the program.

Hint: When writing code for the first method you will need to consider how you will want to read the data back from the file in in the second and third method. The program should continue to run until the user chooses to exit the program.

Make sure that your Java program checks that the file exists before attempting to read from it. If the file does not exist then handle this situation by informing the user that the file does not exist and then create the file by executing the first method.

b) Modify your program (and possibly the methods) so that

  • the user can choose the starting and ending values to be stored in the text file
  • the user can enter the name of the file that is created by the first method
  • the user can enter the name of the file that is to be read by the second method.
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.