CSE 131 Module 1: Types & Names


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 08:59:37 CST 09 January 2015
When you done with this lab, you must be cleared by the TA to receive credit.

Last name WUSTL Key Propagate?
(or your numeric ID) Do not propagate
e.g. Smith j.smith
1 Copy from 1 to all others
2 Copy from 2 to all others

TA: Password: