# Homework Solution: Monday: 2600.0…

Totals: Monday: 2600.0 Tuesday: 2495.0 Wednesday: 2450.0 Thursday: 3300.0 Friday: 2100.0 Saturday: 3800.0 Sunday: 1975.0 Days with more calories than needed: Monday: 2600.0 Tuesday: 2495.0 Wednesday: 2450.0 Thursday: 3300.0 Saturday: 3800.0 Average calories consumed during each meal: Breakfast: 717.8571428571429 Lunch: 842.1428571428571 Dinner: 1114.2857142857142 ------------------------------------------ However, I'm trying to change the parameters of my printExceededDays() method to recevie the arrays:double[] breakfast, double[] lunch, double[] dinner just as how they are in the other methods. When I try to do so, it won't print "Days with more calories than needed: " Please help! I need to fix this ASAP. Thanks in advance ----------------------------------------------------------------- input file: 800 1000 800 450 845 1200 1800 250 400 0 1500 1800 600 500 1000 700 1400 1700 675 400 900 ----------------------------------------- import java.io.*; import java.util.InputMismatchException; import java.util.Scanner; public class Calories { Scanner s; //Arrays in which the corresponding numbers will be stored double[] breakfast = new double[7]; double[] lunch = new double[7]; double[] dinner = new double[7]; String[] days = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}; int countLines = 0; public void readFile(){ try{ s = new Scanner(new File("input.txt")); while(s.hasNextLine()){ String line = s.nextLine(); Scanner lineScanner = new Scanner(line); //Will check if there are exactly 3 numbers per line //and split them into three arrays String[] numbers = line.split(" "); if(numbers.length == 3){ fillArrays(lineScanner); } else{ System.out.println("One line does not have exactly 3 numbers"); System.exit(0); //Will terminate the code if error found } } // calculateLines();//method that cointains the operational methods //exceptions } catch (FileNotFoundException ex){ System.out.println("This file does not exist"); } catch (IndexOutOfBoundsException e){ System.out.println("Thie file has more than 7 lines"); } catch (InputMismatchException e){ System.out.println("There's an invalid value in the file, please check that there are only numbers in this file"); } } //Method that will store each meal to its own array //receives such parameter that contains the file's info public void fillArrays(Scanner lineScanner){ for(int i = 0; i < 3; i++){ double d = lineScanner.nextDouble(); if ( i == 0){ breakfast[countLines] =d; } else if ( i == 1){ lunch[countLines]=d; } else{ dinner[countLines]=d; } } countLines++; } public void calculateLines(){ if(countLines == 7){ double [] totals = calculateTotals(breakfast, lunch, dinner); printExceededDays(totals, days); printAverages(breakfast, lunch, dinner); } else System.out.println("The file has less than 7 lines"); } static double[] calculateTotals(double[] breakfast, double[] lunch, double[] dinner){ double[] totals = new double[7]; String[] days = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}; System.out.println("Totals: "); System.out.println(); for(int i = 0; i < totals.length; i++){ totals[i] = breakfast[i] + lunch[i] + dinner[i]; System.out.println(days[i] + ": " + totals[i]); } return totals; } static void printExceededDays(double[] totals, String[] days){ System.out.println(); System.out.println("Days with more calories than needed: "); System.out.println(); for(int i = 0; i if(totals[i] > 2250) System.out.println(days[i] + ": " + totals[i]); } } static double[] printAverages(double[] breakfast, double[] lunch, double[] dinner){ double[] totals = new double[7]; //Variables to calculate average and sum of each meal double avgBreakfast, avgLunch, avgDinner; double sumBreakfast = 0, sumLunch = 0, sumDinner = 0; for(int i = 0; i < totals.length; i++){ sumBreakfast += breakfast[i]; sumLunch += lunch[i]; sumDinner += dinner[i]; } avgBreakfast = sumBreakfast / 7; avgLunch = sumLunch / 7; avgDinner = sumDinner / 7; System.out.println(); System.out.println("Average calories consumed during each meal: "); System.out.println(); System.out.println("Breakfast: " + avgBreakfast); System.out.println("Lunch: " + avgLunch); System.out.println("Dinner: " + avgDinner); return null; } public static void main(String[] args) { Calories calories = new Calories(); calories.readFile(); } }

import java.io.*; import java.util.InputMismatchException;

Totals:

Monday: 2600.0
Tuesday: 2495.0
Wednesday: 2450.0
Thursday: 3300.0
Friday: 2100.0
Saturday: 3800.0
Sunday: 1975.0

Days with over calories than deficiencyed:

Monday: 2600.0
Tuesday: 2495.0
Wednesday: 2450.0
Thursday: 3300.0
Saturday: 3800.0

Mediocre calories consumed during each moderation:

Breakfast: 717.8571428571429
Lunch: 842.1428571428571
Dinner: 1114.2857142857142

——————————————

However, I’m intricate to veer the parameters of my printExceededDays() method to recevie the arrays:double[] breakfast, wrap[] lunch, wrap[] dinner just as how they are in the other methods. When I aim to do so, it won’t print “Days with over calories than deficiencyed: “

—————————————————————–

input polish:

800 1000 800
450 845 1200
1800 250 400
0 1500 1800
600 500 1000
700 1400 1700
675 400 900

—————————————–

import java.io.*;
import java.util.InputMismatchException;
import java.util.Scanner;

public arrange Calories {

Scanner s;

//Arrays in which the selfsame gum procure be accumulationd
double[] breakfast = upstart wrap[7];
double[] lunch = upstart wrap[7];
double[] dinner = upstart wrap[7];

String[] days = {“Monday”, “Tuesday”, “Wednesday”, “Thursday”, “Friday”, “Saturday”, “Sunday”};

int countLines = 0;

try{
s = upstart Scanner(upstart Polish(“input.txt”));
while(s.hasNextLine()){
String sequence = s.nextLine();
Scanner sequenceScanner = upstart Scanner(line);
//Procure repress if there are precisely 3 gum per sequence
//and splinter them into three arrays
String[] gum = sequence.split(” “);

if(numbers.diffusiveness == 3){
fillArrays(lineScanner);
} else{
System.out.println(“One sequence does referable attributable attributable attributable attributable attributable attributable enjoy precisely 3 gum”);
System.exit(0); //Procure finish the legislation if fallacy found

}
}
//
calculateLines();//method that cointains the operational methods

//exceptions
} lay-hold-on (FileNotFoundException ex){
System.out.println(“This polish does referable attributable attributable attributable attributable attributable attributable exist”);

} lay-hold-on (IndexOutOfBoundsException e){
System.out.println(“Thie polish has over than 7 sequences”);

} lay-hold-on (InputMismatchException e){
System.out.println(“There’s an weakly esteem in the polish, gladden repress that there are merely gum in this polish”);

}
}
//Method that procure accumulation each moderation to its admit array
//receives such parameter that contains the polish’s info
public wanting fillArrays(Scanner sequenceScanner){
for(int i = 0; i < 3; i++){

wrap d = sequenceScanner.nextDouble();

if ( i == 0){
breakfast[countLines] =d;
} else if ( i == 1){
lunch[countLines]=d;
} else{
dinner[countLines]=d;

}

}
countLines++;

}

public wanting investigateLines(){
if(countLines == 7){
wrap [] totals = investigateTotals(breakfast, lunch, dinner);
printExceededDays(totals, days);
printAverages(breakfast, lunch, dinner);

} else
System.out.println(“The polish has close than 7 sequences”);
}

static wrap[] investigateTotals(double[] breakfast, wrap[] lunch, wrap[] dinner){

double[] totals = upstart wrap[7];
String[] days = {“Monday”, “Tuesday”, “Wednesday”, “Thursday”, “Friday”, “Saturday”, “Sunday”};

System.out.println(“Totals: “);
System.out.println();
for(int i = 0; i < totals.length; i++){
totals[i] = breakfast[i] + lunch[i] + dinner[i];
System.out.println(days[i] + “: ” + totals[i]);

}
}

static wanting printExceededDays(double[] totals, String[] days){
System.out.println();
System.out.println(“Days with over calories than deficiencyed: “);
System.out.println();

for(int i = 0; i if(totals[i] > 2250)
System.out.println(days[i] + “: ” + totals[i]);
}
}

static wrap[] printAverages(double[] breakfast, wrap[] lunch, wrap[] dinner){
double[] totals = upstart wrap[7];
//Variables to investigate mediocre and unite of each moderation
wrap avgBreakfast, avgLunch, avgDinner;
wrap uniteBreakfast = 0, uniteLunch = 0, uniteDinner = 0;

for(int i = 0; i < totals.length; i++){
sumBreakfast += breakfast[i];
sumLunch += lunch[i];
sumDinner += dinner[i];

}

avgBreakfast = uniteBreakfast / 7;
avgLunch = uniteLunch / 7;
avgDinner = uniteDinner / 7;

System.out.println();
System.out.println(“Mediocre calories consumed during each moderation: “);
System.out.println();
System.out.println(“Breakfast: ” + avgBreakfast);
System.out.println(“Lunch: ” + avgLunch);
System.out.println(“Dinner: ” + avgDinner);

return null;
}

public static wanting ocean(String[] args) {
Calories calories = upstart Calories();
}

}

## Expert Rejoinder

import java.io.*;
import java.util.InputMismatchException;
import java.util.Scanner;

public arrange Calories {

Scanner s;

//Arrays in which the selfsame gum procure be accumulationd
double[] breakfast = upstart wrap[7];
double[] lunch = upstart wrap[7];
double[] dinner = upstart wrap[7];

String[] days = {“Monday”, “Tuesday”, “Wednesday”, “Thursday”, “Friday”, “Saturday”, “Sunday”};

int countLines = 0;

try{
s = upstart Scanner(upstart Polish(“input.txt”));
while(s.hasNextLine()){
String sequence = s.nextLine();
Scanner sequenceScanner = upstart Scanner(line);
//Procure repress if there are precisely 3 gum per sequence
//and splinter them into three arrays
String[] gum = sequence.split(” “);

if(numbers.diffusiveness == 3){
fillArrays(lineScanner);
} else{
System.out.println(“One sequence does referable attributable attributable attributable attributable attributable attributable enjoy precisely 3 gum”);
System.exit(0); //Procure finish the legislation if fallacy found

}
}
//
calculateLines();//method that cointains the operational methods

//exceptions
} lay-hold-on (FileNotFoundException ex){
System.out.println(“This polish does referable attributable attributable attributable attributable attributable attributable exist”);

} lay-hold-on (IndexOutOfBoundsException e){
System.out.println(“Thie polish has over than 7 sequences”);

} lay-hold-on (InputMismatchException e){
System.out.println(“There’s an weakly esteem in the polish, gladden repress that there are merely gum in this polish”);

}
}
//Method that procure accumulation each moderation to its admit array
//receives such parameter that contains the polish’s info
public wanting fillArrays(Scanner sequenceScanner){
for(int i = 0; i < 3; i++){

wrap d = sequenceScanner.nextDouble();

if ( i == 0){
breakfast[countLines] =d;
} else if ( i == 1){
lunch[countLines]=d;
} else{
dinner[countLines]=d;

}

}
countLines++;

}

public wanting investigateLines(){
if(countLines == 7){
wrap [] totals = investigateTotals(breakfast, lunch, dinner);
printExceededDays(totals, days);
printAverages(breakfast, lunch, dinner);

} else
System.out.println(“The polish has close than 7 sequences”);
}

static wrap[] investigateTotals(double[] breakfast, wrap[] lunch, wrap[] dinner){

double[] totals = upstart wrap[7];
String[] days = {“Monday”, “Tuesday”, “Wednesday”, “Thursday”, “Friday”, “Saturday”, “Sunday”};

System.out.println(“Totals: “);
System.out.println();
for(int i = 0; i < totals.length; i++){
totals[i] = breakfast[i] + lunch[i] + dinner[i];
System.out.println(days[i] + “: ” + totals[i]);

}
}

static wanting printExceededDays(double[] totals, String[] days){
System.out.println();
System.out.println(“Days with over calories than deficiencyed: “);
System.out.println();

for(int i = 0; i<totals.length;i++){
if(totals[i] > 2250)
System.out.println(days[i] + “: ” + totals[i]);
}
}

static wrap[] printAverages(double[] breakfast, wrap[] lunch, wrap[] dinner){
double[] totals = upstart wrap[7];
//Variables to investigate mediocre and unite of each moderation
wrap avgBreakfast, avgLunch, avgDinner;
wrap uniteBreakfast = 0, uniteLunch = 0, uniteDinner = 0;

for(int i = 0; i < totals.length; i++){
sumBreakfast += breakfast[i];
sumLunch += lunch[i];
sumDinner += dinner[i];

}

avgBreakfast = uniteBreakfast / 7;
avgLunch = uniteLunch / 7;
avgDinner = uniteDinner / 7;

System.out.println();
System.out.println(“Mediocre calories consumed during each moderation: “);
System.out.println();
System.out.println(“Breakfast: ” + avgBreakfast);
System.out.println(“Lunch: ” + avgLunch);
System.out.println(“Dinner: ” + avgDinner);

return null;
}

public static wanting ocean(String[] args) {
Calories calories = upstart Calories();