CSE 131 Module 1: Intro and Types & Names


Before beginning any work, do a Team...Pull in your repository.


Nutrition Analyzer

In this lab you develop a simple tool that prints nutrition information about food. This lab is based on what you learned in studio. By completing this lab you demonstrate that you can:


  1. Create a Nutrition Java class in the lab1 package of 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.
  2. Arrange for your program to accept the following inputs:
    The name of this food, provided as a String
    The number of grams of carbohydrates in this food
    The number of grams of fat in this food
    The number of grams of protein in this food
    The number of calories stated on this food's label

    For example, the values for a Snicker bar are:

    name Snickers
    carbs 34.5
    fat 13.6
    protein 4.3
    statedCals 271

    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.

  3. Arrange for your program to produce output such as the following:
    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
      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


  4. To demo your lab, find some food labels (for real or on the web) and run your program with the appropriate values for those foods.

What went wrong? (not required, for your amusement only)

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?

Submitting your work (read carefully)

Last modified 12:58:41 CDT 07 October 2018
When you are done with this lab, you must be cleared by the TA to receive credit.

This demo box is for lab 1
Last name WUSTL Key Propagate?
(NOT your numeric ID) Do not propagate
lower case only
e.g. Smith j.smith

Acknowledgements and assertion of integrity

You must select one of the options below
The work submitted here was performed in accordance with this course's policy on collaboration.
On your honor, you have neither given nor received any unauthorized aid on this assignment.

However, the following TAs, students, or professors were supportive in completing this assignment.
Their help was also in accordance with course policies.

Thanks to (leave blank if appropriate):

In spite of seeking help as allowable by this course's policy on collaboration, you were unable to complete this assignment. No credit will be received for this assignment.

You would like to be contacted by an instructor to facilitate staying on track in this course.

Comments about this:

You have NOT abided by this course's policy on collaboration. No credit will be received for this assignment, but by checking this box, no academic integrity violation will be filed for this assignment.

You would like to be contacted by an intructor to faciliate staying on track in this course.

Comments about this:

TAs double check!
  • This demo box is for lab 1
  • The student has committed and pushed the work, and verified that it appears at bitbucket.
TA: Password: