a method that stores the number of calories and fat grams in a food item". Also include the setters and getters for the field variables, and the additional method they talk about that "returns the percentage of the calories that come from fat".
Include the constructor as the book says "a method that stores the number of calories and fat grams in a food item". Also include the setters and getters for the field variables, and the additional method they talk about that "returns the percentage of the calories that come from fat".
The last paragraph in the book needs clarification. Since the user will be entering the number of fat grams and not the number of calories from fat, the sentence should be more like:
"Because the number of calories from fat cannot be greater than the total number of calories, if the user enters a number for the fat grams that calculates to contain more calories than the total number of calories for the food item, the program should display an error message indicating that the two input numbers are invalid." The program should then prompt for those inputs again, or at least prompt for the fat grams again. It is easier if you just prompt for the fat grams again.
Please remember that all input and output statements must be in the testing program and not in the external class named FatGram.
![**FatGram Class**
Design a class with a method that stores the number of calories and fat grams in a food item. The class should have a method that returns the percentage of calories that come from fat. One gram of fat has 9 calories, so:
\[ \text{Calories from fat} = \text{fat grams} \times 9 \]
The percentage of calories from fat can be calculated as:
\[ \text{Calories from fat} \div \text{total calories} \]
**Demonstrate the class in a program** that asks the user to enter the number of calories and the number of fat grams for a food 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, it should also display a message indicating the food is low in fat.
Because the number of calories from fat cannot be greater than the total number of calories, if the user enters a number for the calories from fat that is greater than the total number of calories, the program should display an error message indicating that the numbers are invalid.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F8abc09d6-17bd-464c-aeb0-aeebdb1f2601%2F6166dac5-1ed6-43d1-8251-883a296a7e61%2Favnv69b.jpeg&w=3840&q=75)

Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images









