3.10. Fat Gram Calculator - Java

Words
188
Reading
1 min
Listen
Play
10y

Starting out with Java: From control structures through objects

Chapter 3

Programming Challenges

10. Fat Gram Calculator

Write a program that asks the user to enter the number of calories and fat grams in a food item. The program should display the percentage of the calories that come from fat. One gram of fat has 9 calories; therefore: 

Calories from fat = Fat grams * 9 

The percentage of calories from fat can be calculated as follows: 

Calories from fat / Total calories 

If the calories from fat are less than 30 percent of the total calories of the food, it should also display a message indicating the food is low in fat. 

Note: The number of calories from fat cannot be greater than the total number of calories in the food item. If the program determines that the number of calories from fat is greater than the number of calories in the food item, it should display an error message indicating that the input is invalid.

Gaddis, Tony (2015-05-29). Starting Out with Java: From Control Structures through Objects (Page 187). Pearson Education. 

Kindle Edition. 

Happy Steeming Everyone! :)

3.10. Fat Gram Calculator - Java | Ecency