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.
  • 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.
  • Add a new method to calculate and return the average (mean) of the values in the array. Display the average in your main program.
  • 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.
  • 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.
  • As per part b of exercise 1 in week 7 your program should
    • allow the user to choose the starting and ending values to be stored in the file,
    • enter the file name of the file to be created,
    • 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.

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.