Objective: The goal of this assignment is to refresh your memory of 1-dimensional arrays, in preparation for the following lab on multi-dimensional arrays.
Background: A local fitness company has contracted you to create a simple diet tracking software that will help clients count calories.
Assignment (part 1): The client will provide data in the form of a text file. There are three numbers on each line, separated by spaces. The numbers represent the number of calories consumed for breakfast, lunch and dinner, respectively. For part 1, you should assume that the file includes data for exactly one week (i.e., 7 lines of text). Your program should read the data from the file into three separate arrays, one each for breakfast lunch and dinner. Then, compute and print out the following information:
Example input file:
200 1000 800 450 845 1200 800 250 400 0 1500 1800 600 500 1000 700 1400 1700 675 400 900You should print an error message and terminate if there are not exactly three numbers on each line, and exactly 7 lines overall.
Assignment (part 2): The client comes back and would like you to make the program more general, so that it can handle any number of days worth of data in a single input file. You no longer know that there will be exactly 7 lines of input, so you program should handle any number of lines. Take your code from part 1 and change the implementation to use the ArrayList data structure instead of arrays to hold the three lists of numbers. See http://download.oracle.com/javase/6/docs/api/java/util/ArrayList.html for more details on ArrayLists. Using this data structure you do not need to know the number of elements in advance. Your program should calculate and print exactly the same information from part 1.
Deliverables: Your TA will instruct you.