Question

In: Computer Science

You are tasked to provide a Fat Gram Calculator program for a local Weight Loss Center....

You are tasked to provide a Fat Gram Calculator program for a local Weight Loss Center. The program should ask the user for the name of a food item, the number of calories and the number of fat grams in the item. The program should display the percentage of calories that come from fat. If the calories from fat are less than 30 percent of the total calories of the food, it should display a message indicating that the food is low in fat. If the percentage is equal to or higher than 30 percent the message should indicate that the food is high in fat.

One gram of fat has 9 calories, so
          calories from fat = fat grams * 9

The percentage of calories from fat can be calculated as
         Percent Fat = Calories from fat / total calories

Input validation: The program should make sure that the number of calories is greater than 0, the number of fat grams is 0 or more, and the number of calories from fat is not greater than the number of calories input.

Solutions

Expert Solution

code:

//import java util

import java.util.Scanner;

//define a class fat gram calculator

class Main

{

//main function

public static void main(String args[])

{

//scanner class

Scanner s=new Scanner(System.in);

//scanner class

Scanner t=new Scanner(System.in);

//while loop

while(true)

{

//print statement to enter disk name

System.out.print("Please enter the name of the dish: ");

//input thr string

String name=s.nextLine();

//print statement for fat

System.out.print("Enter the fat in grams: ");

//input the fat grams

double gm_ft=s.nextDouble();

//print statement for calories

System.out.print("Enter the calories: ");

//input the calories

double cal=s.nextDouble();

if(cal<0 || gm_ft<0 || cal>(gm_ft*9))

//print there is wrong value

System.out.println("error");

//calculation

double p=(gm_ft*9)/cal;

//print calories

System.out.println("The calories percentage = "+(p)+"%");

//if the percentage is less than 0.3

if(p<0.3)System.out.println("The food is low in fat");

//check to continue

System.out.print("Do you want to continue [* to quit]: ");

//onatin input

String F=t.nextLine();

if(F.charAt(0)=='*')break;

}

}

}


Related Solutions

A weight loss program claims that program participants have a mean weight loss of at least...
A weight loss program claims that program participants have a mean weight loss of at least 10 pounds after 1 month. You work for a medical association and are asked to test this claim. A random sample of 30 program participants and their weight losses (in pounds) after 1 month is listed in the table below. Assume the population standard deviation is 3. At α = 0.01, is there enough evidence to reject the program's claim? Samples: 4.7, 6.0, 7.2,...
A weight loss program claims that program participants have a mean weight loss of at least...
A weight loss program claims that program participants have a mean weight loss of at least 10 pounds after 1 month. The weight losses (in pounds) of a random sample of 30 program participants are listed below. At the 1% significance level, is this enough evidence to reject the program’s claim?    4.7         6.0        7.2         8.3       9.2       10.1         14.0       11.7         12.8       10.8 11.0       7.2         8.0        4.7      11.8     10.7          6.1         8.8           7.7         8.5 9.5         10.2        5.6        6.9      7.9         8.6         10.5         9.6           5.7        9.6
A clinic offers a​ weight-loss program. The table below gives the amounts of weight​ loss, in​...
A clinic offers a​ weight-loss program. The table below gives the amounts of weight​ loss, in​ pounds, for a random sample of 20 of its clients at the conclusion of the program. Assume that the data are normally distributed. Complete parts​ (a) and​(b). 10 11 12 24 20 21 7 8 18 19 17 5 15 8 17 16 13 16 14 23 a.Find a 98​% confidence interval for the population mean. The 98% confidence interval is from a lower...
A weight loss program is announced by Health fitness centre claiming weight loss for sure. A...
A weight loss program is announced by Health fitness centre claiming weight loss for sure. A random sample of eight recent participants showed the following weights before and after completing the course. At the 0.01 significance level, can we conclude the students lost weight? Names Before After Hunter 157 153 Cashman 225 209 Mervine 141 147 Massa 152 147 Creola 201 186 Perterson 154 140 Redding 174 160 Poust 185 175 (a) State the null hypothesis and the alternative hypothesis....
Low-fat or low-carb? Are low-fat diets more effective for weight loss? A sample of 58 subjects...
Low-fat or low-carb? Are low-fat diets more effective for weight loss? A sample of 58 subjects went on a low-carbohydrate diet for six months. At the end of that time, the sample mean weight loss was 3.2 kilograms with a sample standard deviation of 5.42 kilograms. A second sample of 60 subjects went on a low-fat diet. Their sample mean weight loss was 2.4 kilograms with a standard deviation of 4.48 kilograms. Can you conclude that the mean weight loss...
A Community Center was interested in the effect of their program on summer loss. Summer loss...
A Community Center was interested in the effect of their program on summer loss. Summer loss is the decrease in academic knowledge from the summer to the Fall of the new year. To test their program, they drew a random sample of 20 students from the program. The students were assessed before and after the 6 week program on a 36 item assessment. Difference scores were calculated for the 20 students and are summarized below. (These scores were calculated by...
Suppose a fitness center has two weight-loss programs. Fifteen students complete Program A, and fifteen students...
Suppose a fitness center has two weight-loss programs. Fifteen students complete Program A, and fifteen students complete Program B. Afterward, the mean and standard deviation of weight loss for each sample are computed (summarized below). What is the difference between the mean weight losses, among all students in the population? Answer with 95% confidence. Prog A - Mean 10.5 St dev 5.6 Prog B - Mean 13.1 St dev 5.2
Fat Percentage Calculator Create a C++ program that allows the user to enter the number of...
Fat Percentage Calculator Create a C++ program that allows the user to enter the number of calories and fat grams in a food. The application should display the percentage of the calories that come from fat. If the calories from fat are less than 30% of the total calories of the food, it should also display a message indicating the food is low in fat. One gram of fat has 9 calories, so: Calories from fat = fat grams *...
Low-fat or low-carb? Are low-fat diets or low-carb diets more effective for weight loss? A sample...
Low-fat or low-carb? Are low-fat diets or low-carb diets more effective for weight loss? A sample of 77 subjects went on a low-carbohydrate diet for six months. At the end of that time, the sample mean weight loss was 4.7 kilograms with a sample standard deviation of 7.16 kilograms. A second sample of 79 subjects went on a low-fat diet. Their sample mean weight loss was 2.6 kilograms with a standard deviation of 5.90 kilograms. Can you conclude that the...
In a weight loss programs, 40 adults used the Atkins weight loss program. After 12 months,...
In a weight loss programs, 40 adults used the Atkins weight loss program. After 12 months, their mean weight loss was found to be 2.1 lb, with a standard deviation of 4.8lb. Construct a 97% confidence interval of the mean weight loss.h
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT