Methods and Arrays

• September 11th, 2013, 08:11 PM
scott201
Methods and Arrays
For this problem I'm supposed to help a client at a local fitness company. The client provides data in the form of a text file. Each row is the number of calories consumed for breakfast, lunch, and dinner and the data included is for one week. (7 lines of text)
I'm supposed to print out: 1. list of the total number of calories consumed each day, 2. average number of calories consumed each day, 3. average number of calories consumed in each of the three meals, 4. the maximum number of calories consumed in any specific day, 5. and the maximum number of calories consumed in any one meal. All of these must have their own seperate methods and not be all put into the main method.
This is what I have so far but am having trouble actually starting each method.
Any help of any kind would be greatly appreciated!

The text file includes:
200 1000 800
450 845 1200
800 250 400
0 1500 1800
600 500 1000
700 1400 1700
675 400 900

Code :

```import java.util.*; import java.io.*;   public class dietTracking { public static void main(String[] arg){ readData("sample.in"); } static void readData(String fileName){ try{ File input=new File(fileName); Scanner scanLine=new Scanner(input); //To read line from the text file String line=scanLine.nextLine(); //Read whole line from the file Scanner scanNumber=new Scanner(line); //To read numbers from the Line buffer for(int meal=0; meal<3; meal++){ //To read three numbers from the line buffer if(scanNumber.hasNextInt()){ //Check whether number is present in the line int calories=scanNumber.nextInt(); //Read number from the line buffere and store System.out.print(calories+" "); } } } catch (FileNotFoundException e){ //catch exception if input file is missing System.out.println(e); } } }```
• September 11th, 2013, 10:07 PM
jps
Re: Methods and Arrays
Quote:

Originally Posted by scott201
This is what I have so far but am having trouble actually starting each method.

Plan ahead how to solve the problem first, (on paper perhaps) and then translate the solution into code. Work on one problem at a time.
Pick one to begin with, write out the plan of how to solve it, and post the plan here with your question if you get stuck