Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this assignment we will practice using a module and a class that have been given to us . You are provided with a file
In this assignment we will practice using a module and a class that have been given to us
You are provided with a filefoodpysee attached file later This file contains code that implements a very basic food item object. It has a constructor, getter, setter, and helper methods. Take a look at theFoodItemclass and familiarize yourself with those methods.
You are also provided with a fileinputroutinespynot shown You will use two functions in this file to handle input validation. While you cannot view theinputroutinespyfile your program can access its content by importing it The two functions in the file which are relevant to this assignment are documented below:
Function: intInRangelower upper
Purpose: read an integer from keyboard and validate that is a value between lower and upper
Parameters: lower and upper are two integers to represent lower and upper bounds
Return value: a valid integer entered by the user
Sample call: value intInRange
Function: floatInRangelower upper
Purpose: read a float from keyboard and validate that is a value between lower and upper
Parameters: lower and upper are two float to represent lower and upper bounds
Return value: a valid float entered by the user
Sample call: value floatInRange
Your task is to write the main script that creates aFoodItemobject displays the basic object's information, then ask the user how many servings they have consumed and display the total calories consumed.
Here are some additional specifications:
The user of the program must provide the food item's name, serving size, grams of fat, carbs, and protein per serving.
Serving size is an integer value between and inclusive
Grams of fat per serving is a float value between and inclusive
Grams of carbs per serving is a float value between and inclusive
Grams of protein per serving is a float value between and inclusive
Instantiate aFoodItemobject with the data provided by the user.
Display theFoodItems name, serving size, grams of fat, carbs, and protein per serving, as well as the number of calories per serving.
Next the user should enter the number of servings consumed
The number of servings is an integer value between and inclusive
Calculate and display the total number of calories consumed.
Notes
Floatingpoint values must be displayed with decimal digits after the decimal point.
You are not allowed to modify thefoodpyfile or theFoodItemclass
Make sure you include a header comment at the top of your file.
Below there are a couple of sample runs:
Enter food item's name: Chocolate Bar
Enter the serving size in grams or mL for liquids:
Enter the grams of fat per serving:
Enter the grams of carbs per serving:
Enter the grams of protein per serving:
Nutritional information per serving of Chocolate Bar
Serving Size: grams mL
Fat: grams
Carbohydrates: grams
Protein: grams
Number of calories for serving:
Enter the number of servings consumed:
Number of calories for servings:
Enter food item's name: Whole Milk
Enter the serving size in grams or mL for liquids:
Enter the grams of fat per serving:
Enter the grams of carbs per serving:
Enter the grams of protein per serving:
Nutritional information per serving of Whole Milk
Serving Size: grams mL
Fat: grams
Carbohydrates: grams
Protein: grams
Number of calories for serving:
Enter the number of servings consumed:
Number of calories for servings:
You may find the following site useful to compare your output against the expected program output:Diffchecker
The purpose of this problem is to practice using classes and modules.
Please make sure to submit a wellwritten program. Good identifier names, useful comments, and spacing will be some of the criteria that will be used when grading this assignment.
This assignment can be and must be solved using only the materials that have been discussed in class. Do not look for alternative methods that have not been covered as part of this course.
How your program will be graded:
correctness: the program works and performs all tasks correctly: autograded by Zybooks
complies with requirements input validation, correct use of theFoodItemclass methods: TAs
code style: good variable names, comments, proper indentation and spacing: TAs
# TODO: your header comment goes here
# TODO: import the modules needed to use the FoodItem class the and input validation functions
# main routine
if namemain:
# TODO: WRITE THE MAIN ROUTINE HERE
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started