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 9.
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
275
8
Calories in Pizza per serving: 309.38
use the following javacode:
package com.me.calories;
import java.util.Scanner;
public class calories {
/**
* @param args the command line arguments
*/
public static void main(String[] args){
Scanner input=new Scanner(System.in);
System.out.println("Please enter the food item name:");
String food_item = input.next();
System.out.println("Please enter the fat content in grams:");
int fat_content = input.nextInt();
System.out.println("Please enter the number of servings:");
double servings = input.nextDouble();
/*int total_calories = fat_content *9;
double cps = total_calories/servings;*/
double cps=cal_cps(fat_content,servings);
System.out.println("Calorises per serving for" + food_item +" is "+ cps);
input.close();
}
public static double cal_cps(int fc, double servings){
int total_calories = fc *9;
double calories_per_serving = total_calories / servings;
return calories_per_serving;
}
}
Describe the solution to the following problem

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!