This is a continuation of Exercise 2 from week 6 practical exercises. Import a copy of the two java files, Expenses.java and ExpensesDemo.java that you developed in Exercise 2 Week 6 into your week 7 project in Eclipse.

Kevin Malone has realised that it would be easier for him to be able to enter the weekly sales and expenses figures for each month into a text file that your program could then process.

a) Modify your program (ExpensesDemo.java) to read the data from the file MalonesCones.txt instead of from the keyboard (ie, your program will no longer need to ask the user for the month name, number of weeks in the month or the weekly sales and expenses values since these are now in the text file) instantiating an Expenses object for each month that is read from the file. Note: the code in the Expenses class should not need to be modified.

An example of the file MalonesCones.txt has been included in this week's practical zip file. MalonesCones.txt contains data in the following format (suggestion: open the file in a text editor to confirm that you understand the structure and organisation of the data in the file):

February 4 month namenumber of weeks in month< eoln>
200 300 sales week 1expenses week 1< eoln>
300 450 sales week 2expenses week 2< eoln>
350 250 sales week 3expenses week 3
275 275 sales week 4expenses week 4< eoln>
< repeat pattern for subsequent months>

Use the example input file to test your code. 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 obtain a new file name/location from the user. You should also ensure that your code works correctly for different length files (ie, the input files used for marking your program may contain more or less lines of text than the example file provided).

b) The program will need to generate the on-screen report for Kevin as per the following example output:

For Month of February:
Balance: $-150.00
Total Sales: $1125.00
Total Expenses: $1275.00
Keleven: $150.00

For Month of March:
Balance: $25.00
Total Sales: $1325.00
Total Expenses: $1300.00
Keleven: $0.00

For Month of April:
Balance: $-256.80
Total Sales: $1103.05
Total Expenses: $1359.85
Keleven: $256.80

c) The program will need to generate a text file (expenseSummary.txt) containing the following information for each month that was processed from the MalonesCones.txt file:

  • Month Name
  • Month Balance
  • Total Sales
  • Total Expenses
  • Keleven

Each month's data is to be on a separate line with each data value separated by a comma. Hence, the expenseSummary.txt file should contain data in the following format:

February,-150.00,1125.00,1275.00,150.00
March,25.00,1325.00,1300.00,0.00
April,-256.80,1103.05,1359.85,256.80

This file format is commonly known as a CSV file (comma separated value).

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.