Complete the program by filling In the missing code. The program below should of
ID: 3671650 • Letter: C
Question
Complete the program by filling In the missing code. The program below should of Jan of tomato sauce used in a restaurant. The code asks the user bow many days to consider. and the result is saved in the variable days. Next, the program should ask the user how many jars were used cm the first day and save the result. The program should repeat the request foe the number of times specified ü>> the variable days However, the message asking for the jars used 00 the first day should be different than on the other days The program should calculate jars Total, the total number of)an used on all days Also, the program should calculate lot at Cost, the cost of all of the jars. Finally the program outputs and In 4 days, the restaurant used a total of 2-1 jars of tomato sauce at a coot ofExplanation / Answer
import java.util.*;
public class Jars {
public static void main(String[] args) {
int days = 0;
int jarsUsed = 0; //Number of jars used in a day
int jarsTotal = 0; //Total number of jars on all days
double totalCost = 0; // Total cost of all jars
double price = 2.29; //Price of one jar
Scanner myScanner = new Scanner(System.in);
System.out.println("I will keep track of the jars of tomato sauce used.");
System.out.println("How many days should I consider?");
days = myScanner.nextInt();
for(int i=1; i<=days; i++){
if(i==1)// for first day
System.out.println("How many jars were used on the FIRST day?");
else // rest of day
System.out.println("How many jars were used on the NEXT day?");
jarsUsed = myScanner.nextInt();
jarsTotal = jarsTotal + jarsUsed; // Adding current day used jars in total
}
totalCost = jarsTotal*price; // calculating total cost
System.out.print("In "+days+"days, the restaurant used a total of");
System.out.println(jarsTotal+"jars of tomato sauce at a cost of $"+totalCost+".");
}
}
/*
OUTPUT:
I will keep track of the jars of tomato sauce used.
How many days should I consider?
4
How many jars were used on the FIRST day?
2
How many jars were used on the NEXT day?
6
How many jars were used on the NEXT day?
1
How many jars were used on the NEXT day?
5
In 4days, the restaurant used a total of14jars of tomato sauce at a cost of $32.06.
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.