Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1) Class name: NumberFile.java a) Write a method to create a text file named numbers.txt that is to contain the whole numbers 101 to 10000
1) Class name: NumberFile.java 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. The program should continue to run until the user chooses to 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. 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 i) 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 iii) the user can enter the name of the file that is to be read by the second method
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started