- In this lab you must create and code a simple program that prints nutrtional information about food. You have done similar activities in studio.Review or reference the studio exercises as necessary.
- Code is distributed to you throughout the semester, so you may need to update your repository to see the files for this lab:
- In the package explorer, right- (control-) clock on your project name, choose Team…Update, and supply your credentials.
- In the labs source folder you should see a lab1 package.
- Find and open the lab1 package in the labs source folder.
The lab1 class is currently empty, but don't let that bother you. Right (control) click on lab1 and create a new class called Nutrition.
For example, the values for a Snicker bar are:
At this point, you should be thinking about the data types you would use to represent each of the above items. We tell you that the name is a String, but what about the other inputs?
The above example is provided to inspire your thinking.
To accept the inputs, use the same code we used in studio. Just after the main method declaration, you should have the line:ArgsProcessor ap = new ArgsProcessor(args);This will likely show an error because eclipse doesn't know about ArgsProcessor. Do you remember how to fix this? Ask if you need help.
After that, you should initialize your inputs using code modeled after the code you read and wrote in studio.
Eclipse will help you out here: If you have typed ap. and pause, eclipse will show you the possible ways of continuing. For example, nextInt(String) is one way to keep going. That call will prompt the user for an int displaying the provided String as the prompting message.
Snickers has 34.5 grams of carbohydrates = 138.0 Calories 13.6 grams of fat = 122.4 Calories 4.3 grams of protein = 17.2 Calories This food is said to have 271 (available) Calories. With 6.6 unavailable Calories, this food has 1.65 grams of fiber Approximately 50.9% of your food is carbohydrates 45.2% of your food is fat 6.3% of your food is protein This food is acceptable for a low-carb diet? false This food is acceptable for a low-fat diet? false By coin flip, you should eat this food? true
In the above example, based on carbohydrates, fat, and protein, the food contains 277.6 Calories. However, the label claims a modest 271 Calories. Thus, 6.6 Calories are unavailable and are attributed to dietary fiber.
From this we can compute 6.6 / 4 = 1.65 grams of the stated carbohydrates are fiber.
You must arrange for your percentages to exactly this precise. This will take some thought, but it can be done using what is taught in the book: int operations, double operations, casting, and Math.round(…).You are not allowed to use printf or other functions you may find that would accomplish this task. You have to figure out how to do it using what you have learned in this module.
For the output lines whose conclusions are true or false, define an appropriately named boolean variable in your program and set it equal to the expression that determines its value.
When you print the value it will print as true or false.
I know of a person who took Chemistry and learned that a calorie of energy is required to raise the temperature of a gram of water 1 degree Centigrade.
This gave him the idea that he could lose a lot of weight by drinking ice water, as follows. His body would be called upon to raise the temperature of that cold water to 98.6 degrees Fahrenheit. So if the water starts at 40 degrees Fahrenheit, then his body must raise each gram of that water about almost 60 degrees Fahrenheit, or about 33 degrees Centigrade.
A gram of water is a mL in volume. Thus, each liter of water should cause the body to expend 33,000 Calories. There are about 3,500 Calories in a pound of fat, so drinking the liter of water should cause about 10 pounds of fat to burn.
This person tried this but did not notice much fat loss at all. Can you explain the epic fail here?
When you done with this lab, you must be cleared by the TA to receive credit.
- Commit all your work to your repository
- Fill in the form below with the relevant information
- Have a TA check your work
- The TA should check your work and then fill in his or her name
- Click OK while the TA watches