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
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); } } }