Problem

FatGram ClassDesign a class with a method that stores the number of calories and fat grams...

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 the calories that come from 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:

Calories from fat ÷ 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% of the total calories of the food, 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.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT