# Answered Essay: Calorie intake data from a person is provided in a text file named food.txt. There are three numbers on each line, separated by space

I have these 3 methods written for the assignment below but I need help writing the rest of the code. Need to read from a file then I can use my methods, also need to print an error message and terminate if there are not exactly three numbers on each line and exactly 7 lines overall. Assignment is below the 3 methods. Thank you

{

for(int i=0;i<7;i++)

{

int sum=breakFast[i]+lunch[i]+dinner[i];

System.out.println((i+1)+” day the calorie consumed is “+sum);

}

}

public static void moreCaloriesDay(int[] breakFast,int[] lunch,int[] dinner)

{

for(int i=0;i<7;i++)

{

int sum=breakFast[i]+lunch[i]+dinner[i];

if(sum>2250)

System.out.println((i+1)+” day the calories consumed more than 2250 “);

}

}

public static void avgCalories(int[] breakFast,int[] lunch,int[] dinner)

{

for(int i=0;i<7;i++)

{

int sum=breakFast[i]+lunch[i]+dinner[i];

double avg=sum/3.0;

System.out.println((i+1)+ ” the avg calories consumed is “+avg);

}

In Java

Calorie intake data from a person is provided in a text file named food.txt. There are three numbers on each line, separated by spaces. The numbers represent the number of calories consumed for breakfast, lunch and dinner. 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: 1. a list of total calories consumed each day 2. a list of days when more than 2250 calories are consumed 3. average calories consumed during each of the three meals. YOU MUST WRITE A METHOD WITH EXACTLY THREE ARRAY PARAMETERS TO COMPUTE EACH OF THE THREE LISTED ITEMS ABOVE AND DISPLAY THE RESULT.YOU SHOULD PRINT AN ERROR MESSAGE AND TERMINATE IF THERE ARE NOT EXACLTY THREE NUMBERS ON EACH LINE AND EXACTLY 7 LINES OVERALL.

Hi,
Here is the complete code you can use,
Public class CalorieTracker

{

```private static final String FILENAME = "pathtofilefood.txt"; // file name here

public static void main(String[] args) {
int count=0;
String line;
int[] breakfast= new int[10];
int[] lunch= new int[10];
int[] dinner= new int[10];
```
```                        while ((line= b.readLine()) != null && count<10) {
String[] x= line.split(" "); // split each line by space
```

if(x.length!=3) // if exactly 3 numbers not present

{

System.out.println(“Every line should contain exactly 3 values”);
return;

}
breakfast[count]=x[0]; //setting values
lunch[count]=x[1];
dinner[count]=x[2];
count++;

```                        }
if(count>7) //if more than 7 lines
{
System.out.println("file should contain only 7 lines");
return;
}
sumCaloriesPerday(breakfast,lunch,dinner);
moreCaloriesDay(breakfast,lunch,dinner);
avgCalories(breakfast,lunch,dinner);
```
```                } catch (IOException e) {
System.out.println(e.printStackTrace());
}
```

}

public sumCaloriesPerday(int[] breakFast,int[] lunch,int[] dinner)

{

for(int i=0;i<7;i++)

{

int sum=breakFast[i]+lunch[i]+dinner[i];

System.out.println((i+1)+” day the calorie consumed is “+sum);

}

}

public static void moreCaloriesDay(int[] breakFast,int[] lunch,int[] dinner)

{

for(int i=0;i<7;i++)

{

int sum=breakFast[i]+lunch[i]+dinner[i];

if(sum>2250)

System.out.println((i+1)+” day the calories consumed more than 2250 “);

}

}

public static void avgCalories(int[] breakFast,int[] lunch,int[] dinner)

{

for(int i=0;i<7;i++)

{

int sum=breakFast[i]+lunch[i]+dinner[i];

double avg=sum/3.0;

System.out.println((i+1)+ ” the avg calories consumed is “+avg);

}

}

Pages (550 words)
Approximate price: -

Help Me Write My Essay - Reasons:

Best Online Essay Writing Service

We strive to give our customers the best online essay writing experience. We Make sure essays are submitted on time and all the instructions are followed.

Our Writers are Experienced and Professional

Our essay writing service is founded on professional writers who are on stand by to help you any time.

Free Revision Fo all Essays

Sometimes you may require our writers to add on a point to make your essay as customised as possible, we will give you unlimited times to do this. And we will do it for free.

Timely Essay(s)

We understand the frustrations that comes with late essays and our writers are extra careful to not violate this term. Our support team is always engauging our writers to help you have your essay ahead of time.

Customised Essays &100% Confidential

Our Online writing Service has zero torelance for plagiarised papers. We have plagiarism checking tool that generate plagiarism reports just to make sure you are satisfied.

Try it now!

## Calculate the price of your order

Total price:
\$0.00

How it works?

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

HOW OUR ONLINE ESSAY WRITING SERVICE WORKS

Let us write that nagging essay.

By clicking on the "PLACE ORDER" button, tell us your requires. Be precise for an accurate customised essay. You may also upload any reading materials where applicable.

Pick A & Writer

Our ordering form will provide you with a list of writers and their feedbacks. At step 2, its time select a writer. Our online agents are on stand by to help you just in case.

Editing (OUR PART)

At this stage, our editor will go through your essay and make sure your writer did meet all the instructions.