Answered step by step
Verified Expert Solution
Question
1 Approved Answer
-------- NumberFile.java: import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.InputStreamReader; import java.io.PrintStream; public class NumberFile { public void writeToFile(String filepath, int lowerBound, int
--------
NumberFile.java:
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.InputStreamReader; import java.io.PrintStream; public class NumberFile { public void writeToFile(String filepath, int lowerBound, int upperBound) throws Exception { // constructing the writer BufferedWriter writer = new BufferedWriter(new FileWriter(filepath)); // writing the numbers in the range for(int number = lowerBound; number a. This is a continuation of Exercise 1 from week 7 practical exercises. Import a copy of NumberFile.java (from week 7) into your week 8 project in Eclipse. Modify your solution code as follows: Modify the second method (the method that reads the data from the file into memory) so that the data is read from the file into an array of appropriate data type. Assume that the array can store a maximum of 5000 numbers. Your method will need to ensure that a maximum of 5000 numbers are read from the file even if there are more than 5000 values in the file. You cannot assume that there will always be 5000 values in the file. The method should no longer display the values to the screen. b. Modify the third method (the method that numerically added the values from the file) so that the sum is calculated from the array that was created in part a above. The method will need to return the sum. Display the total (sum) in your main program. c. Add a new method to calculate and return the average (mean) of the values in the array. Display the average in your main program. d. Add a new method to display the contents of the array. Consider that the logical end of the array may not be the physical end of the array. e. Your program must allow the user to choose if they want to create the file, read the file content into an array, calculate and display the total from the array, calculate and display the average of the array content, display the array content, or exit the program. The program should continue to run until the user chooses to exit the program. f. As per part b of exercise 1 in week 7 your program should i. allow the user to choose the starting and ending values to be stored in the file, ii. enter the file name of the file to be created, iii. and enter the file name for the file to be read by the program. Test the program with different sized files with different sets of numbers. Make sure your code works correctly if the file isn't found, if it exists but doesn't have any data in it, or, if the file has too many values to fit into the array. Your solution must incorporate appropriate methods utlising appropriate parameter passing
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