Assignment #1 Solution

\$30.00

Category:

Description

Objective: The goal of this assignment is to refresh your skill of 1-dimensional arrays. In addition, you will become familiar with file reading.

Background: Within a healthy, balanced diet, a grownup needs 2,250 calories a day.

You will write a software to track calorie intake of a person.

Assignment: Calorie intake data from a person is provided in a text file named input.txt. There are three numbers on each line, separated by spaces. The numbers represent the number of calories consumed for breakfast, lunch and dinner, respectively. The file includes data for exactly one week starting from Monday. That is, the file contains seven lines of text. The topmost line is for Monday and the line at the bottom is for Sunday. Your program should read the data from the file into three separate arrays, one for breakfast, one for lunch, and one for dinner. Then, compute and print out the following information:

• a list of total calories consumed each day

• a list of days when more calories than required are consumed

• average calories consumed during each of the three meals

You must write a method with exactly three array parameters to compute each of the listed items above and display the result.

Example input file:

800 1000 800

450 845 1200

1800 250 400

0 1500 1800

600 500 1000

700 1400 1700

675 400 900

You should print an error message and terminate if there are not exactly three numbers on each line, and exactly 7 lines overall.

Deliverables: The name of your source file must be Calories.java. It must be submitted via Blackboard. Your TAs will let you know about any other requirements.

error: Content is protected !!