Question: Describe the solution to the following problem using the flowchart. We are required to determine how many calories a food item has per serving due
Describe the solution to the following problem using the flowchart.
We are required to determine how many calories a food item has per serving due to its fat content.
The algorithm accepts the name of food item, the number of grams of fat and the number of servings. The name of the food item is a String variable. Remember that string values are always enclosed in
Calculate the number of calories in the food item due to fat content, which is computed by multiplying fat grams and calories per gram. Assume the calories per gram are
Now, calculate the number of fat calories per serving use division and display it For reference, here are the two sample output screen shots.
Enter name of food item, fatgrams and number of servings:
pizza
Calories in Pizza per serving:
use the following javacode:
package com.mecalories;
import java.util.Scanner;
public class calories
@param args the command line arguments
public static void mainString args
Scanner inputnew ScannerSystemin;
System.out.printlnPlease enter the food item name:";
String fooditem input.next;
System.out.printlnPlease enter the fat content in grams:";
int fatcontent input.nextInt;
System.out.printlnPlease enter the number of servings:";
double servings input.nextDouble;
int totalcalories fatcontent ;
double cps totalcaloriesservings;
double cpscalcpsfatcontent,servings;
System.out.printlnCalorises per serving for" fooditem is cps;
input.close;
public static double calcpsint fc double servings
int totalcalories fc ;
double caloriesperserving totalcalories servings;
return caloriesperserving;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
