Assignment 13
Due Friday, May 29 at 11:59pm on Canvas


Important: To receive credit, you must only use concepts and methods taught in class to complete these assignments (or you will receive a 0)



Pair Programming Required (or You Will Receive a 0)
  • Both partners fill in, sign, date, and submit the pair programming contract
  • Upload the document(s) along with your assignment code to Canvas.
  • No extra credit if you do not submit the contract along with your code to Canvas
  • Please make sure both your names are on your file (hint: use a comment).
  • If you need help finding a partner, please contact me as soon as possible.


Assignment 13: Fiber Counter (10 pts)

  • Fiber is a type of carbohydrate that the body can’t digest.
  • Though most carbohydrates are broken down into sugar molecules, fiber cannot be broken down into sugar molecules, and instead it passes through the body undigested.
  • Fiber helps regulate the body’s use of sugars, helping to keep hunger and blood sugar in check.
  • Adequate daily fiber intake appears to reduce the risk of developing various conditions, including heart disease, diabetes, diverticular disease, and breast cancer. [1]
  • Fiber also appears to be an important component in maintaining a healthy weight. Some studies indicate that the resting metabolism of people who eat a lot of fiber may be higher than those who eat low amounts of fiber (presumably due to the increased activity of their digestive tracks) [2]
  • Although ancient humans and modern-day native populations both consume(d) upwards of 100 grams of fiber per day, the current recommendation is that people eat an average of 30 grams/day [3].
  • The average American only consumes about 15 grams/day [1]
  • Note that fiber is found only in plant foods including fruits, vegetables, legumes, nuts and seeds.
  • In this program we will write a fiber counter, to help our users track their daily fiber consumption.
  • To begin, copy and paste the starter code into a new Java file named Fiber.
  • Then, fill in the missing parts of the program where indicated in the comments.
  • Note that your program must use a do-while loop (where indicated in the starter code) to receive full credit.
  • It must also handle the the type of error presented in class:
    • The extra '\n' that can cause problems when mixing input.nextDouble() and input.nextLine().
    • Please see Lesson 14 class notes for examples of this problem, and its solution.
  • Once your program is working identically to the sample output, upload it to Canvas.

Starter Code:

/**
 * @author
 * @author
 * CIS 36A, Assignment 13
 */

import java.util.Scanner;

public class Fiber {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("Welcome to the fiber counter!\n"
                + "Let's calculate your daily fiber consumption for the day.");
        String date = "", response = "";
        double numServings = 0.0;
        double totalFiber = 0.0;
       
        //below are the grams of fiber per serving of each menu option
        final double APPLE = 3.7;
        final double BEANS = 14.7;
        final double WHITE_BREAD = 1.0;
        final double WHEAT_BREAD = 2.0;
        final double BURGER = 2.0; //2 grams due to the burger bun
        final double CARROT = 2.0;
        final double CHICKEN = 0.0;
        final double EGG = 0.0;
        final double PASTA = 2.0;
        final double POTATO = 2.0;
        final double RASPBERRY = 8.4;
        final double BROWN_RICE = 3.5;
        final double WHITE_RICE = 1.0;
        final double STRAWBERRY = 3.4;
        final double STEAK = 0.0;
           
        //use a do-while loop here
            System.out.println("\nPlease select from the following list of foods:\n");
            System.out.println("1. Apple (1)");
            System.out.println("2. Beans (1 cup)");
            System.out.println("3. Bread - White (1 slice)");
            System.out.println("4. Bread - Whole Wheat (1 slice)");
            System.out.println("5. Burger (1)");
            System.out.println("6. Carrot (1 medium)");
            System.out.println("7. Chicken (8 oz)");
            System.out.println("8. Egg (1)");
            System.out.println("9. Pasta (1 cup)");
            System.out.println("10. Potato (1)");
            System.out.println("11. Raspberries (1 cup)");
            System.out.println("12. Rice - Brown (1 cup)");
            System.out.println("13. Rice - White (1 cup)");
            System.out.println("14. Strawberries (1 cup)");
            System.out.println("15. Steak (8 ozs)");
            System.out.print("\nEnter your selection or X to exit: ");
            response = input.nextLine();
            //add code inside loop here
        //end loop
        System.out.println("\nHere is your fiber summary for " + date + ":\n");
        System.out.printf("Total grams consumed: %.1f\n", totalFiber);
       
        if(//fiber is less than 15) {
            System.out.println("You need to eat A LOT more fiber. \nYou should double or triple your intake.");
        } else if (//fiber is between 15 and 30) {
            System.out.println("You eat the average amount of daily fiber for an American.\n"
                    + "You need to increase your intake to at least 30 grams/day.");
        } else if (//fiber is between 30 and 40) {
            System.out.println("You eat the recommended daily allowance of fiber, but you could eat more.");
        } else {
            System.out.println("You're a fiber superstar! Keep up the good work!");
        }

        input.close();
    }
}

//Source of fiber information for foods

Sample output:

Welcome to the fiber counter!
Let's calculate your daily fiber consumption for the day.

Please select from the following list of foods:

1. Apple (1)
2. Beans (1 cup)
3. Bread - White (1 slice)
4. Bread - Whole Wheat (1 slice)
5. Burger (1)
6. Carrot (1 medium)
7. Chicken (8 oz)
8. Egg (1)
9. Pasta (1 cup)
10. Potato (1)
11. Raspberries (1 cup)
12. Rice - Brown (1 cup)
13. Rice - White (1 cup)
14. Strawberries (.5 cup)
15. Steak (8 ozs)

Enter your selection or X to exit: 3
Now enter the number of servings: 2

You selected 2.0 servings of white bread.

Please select from the following list of foods:

1. Apple (1)
2. Beans (1 cup)
3. Bread - White (1 slice)
4. Bread - Whole Wheat (1 slice)
5. Burger (1)
6. Carrot (1 medium)
7. Chicken (8 oz)
8. Egg (1)
9. Pasta (1 cup)
10. Potato (1)
11. Raspberries (1 cup)
12. Rice - Brown (1 cup)
13. Rice - White (1 cup)
14. Strawberries (.5 cup)
15. Steak (8 ozs)

Enter your selection or X to exit: 8
Now enter the number of servings: 3

You selected 3.0 servings of egg.

Please select from the following list of foods:

1. Apple (1)
2. Beans (1 cup)
3. Bread - White (1 slice)
4. Bread - Whole Wheat (1 slice)
5. Burger (1)
6. Carrot (1 medium)
7. Chicken (8 oz)
8. Egg (1)
9. Pasta (1 cup)
10. Potato (1)
11. Raspberries (1 cup)
12. Rice - Brown (1 cup)
13. Rice - White (1 cup)
14. Strawberries (.5 cup)
15. Steak (8 ozs)

Enter your selection or X to exit: 5
Now enter the number of servings: 1

You selected 1.0 servings of burger.

Please select from the following list of foods:

1. Apple (1)
2. Beans (1 cup)
3. Bread - White (1 slice)
4. Bread - Whole Wheat (1 slice)
5. Burger (1)
6. Carrot (1 medium)
7. Chicken (8 oz)
8. Egg (1)
9. Pasta (1 cup)
10. Potato (1)
11. Raspberries (1 cup)
12. Rice - Brown (1 cup)
13. Rice - White (1 cup)
14. Strawberries (.5 cup)
15. Steak (8 ozs)

Enter your selection or X to exit: 10
Now enter the number of servings: 1

You selected 1.0 servings of potato.

Please select from the following list of foods:

1. Apple (1)
2. Beans (1 cup)
3. Bread - White (1 slice)
4. Bread - Whole Wheat (1 slice)
5. Burger (1)
6. Carrot (1 medium)
7. Chicken (8 oz)
8. Egg (1)
9. Pasta (1 cup)
10. Potato (1)
11. Raspberries (1 cup)
12. Rice - Brown (1 cup)
13. Rice - White (1 cup)
14. Strawberries (.5 cup)
15. Steak (8 ozs)

Enter your selection or X to exit: 15
Now enter the number of servings: 1.5

You selected 1.5 servings of steak.

Please select from the following list of foods:

1. Apple (1)
2. Beans (1 cup)
3. Bread - White (1 slice)
4. Bread - Whole Wheat (1 slice)
5. Burger (1)
6. Carrot (1 medium)
7. Chicken (8 oz)
8. Egg (1)
9. Pasta (1 cup)
10. Potato (1)
11. Raspberries (1 cup)
12. Rice - Brown (1 cup)
13. Rice - White (1 cup)
14. Strawberries (.5 cup)
15. Steak (8 ozs)

Enter your selection or X to exit: 6
Now enter the number of servings: 1

You selected 1.0 servings of carrot.

Please select from the following list of foods:

1. Apple (1)
2. Beans (1 cup)
3. Bread - White (1 slice)
4. Bread - Whole Wheat (1 slice)
5. Burger (1)
6. Carrot (1 medium)
7. Chicken (8 oz)
8. Egg (1)
9. Pasta (1 cup)
10. Potato (1)
11. Raspberries (1 cup)
12. Rice - Brown (1 cup)
13. Rice - White (1 cup)
14. Strawberries (.5 cup)
15. Steak (8 ozs)

Enter your selection or X to exit: X
Now enter today's date: May 22, 2020

Here is your fiber summary for May 22, 2020:

Total grams consumed: 8.0
You need to eat A LOT more fiber.
You should double or triple your intake.


Sample output:

Welcome to the fiber counter!
Let's calculate your daily fiber consumption for the day.

Please select from the following list of foods:

1. Apple (1)
2. Beans (1 cup)
3. Bread - White (1 slice)
4. Bread - Whole Wheat (1 slice)
5. Burger (1)
6. Carrot (1 medium)
7. Chicken (8 oz)
8. Egg (1)
9. Pasta (1 cup)
10. Potato (1)
11. Raspberries (1 cup)
12. Rice - Brown (1 cup)
13. Rice - White (1 cup)
14. Strawberries (.5 cup)
15. Steak (8 ozs)

Enter your selection or X to exit: 4
Now enter the number of servings: 2

You selected 2.0 servings of whole wheat bread.

Please select from the following list of foods:

1. Apple (1)
2. Beans (1 cup)
3. Bread - White (1 slice)
4. Bread - Whole Wheat (1 slice)
5. Burger (1)
6. Carrot (1 medium)
7. Chicken (8 oz)
8. Egg (1)
9. Pasta (1 cup)
10. Potato (1)
11. Raspberries (1 cup)
12. Rice - Brown (1 cup)
13. Rice - White (1 cup)
14. Strawberries (.5 cup)
15. Steak (8 ozs)

Enter your selection or X to exit: 11
Now enter the number of servings: 1

You selected 1.0 servings of raspberries.

Please select from the following list of foods:

1. Apple (1)
2. Beans (1 cup)
3. Bread - White (1 slice)
4. Bread - Whole Wheat (1 slice)
5. Burger (1)
6. Carrot (1 medium)
7. Chicken (8 oz)
8. Egg (1)
9. Pasta (1 cup)
10. Potato (1)
11. Raspberries (1 cup)
12. Rice - Brown (1 cup)
13. Rice - White (1 cup)
14. Strawberries (.5 cup)
15. Steak (8 ozs)

Enter your selection or X to exit: 14
Now enter the number of servings: .5

You selected 0.5 servings of strawberries.

Please select from the following list of foods:

1. Apple (1)
2. Beans (1 cup)
3. Bread - White (1 slice)
4. Bread - Whole Wheat (1 slice)
5. Burger (1)
6. Carrot (1 medium)
7. Chicken (8 oz)
8. Egg (1)
9. Pasta (1 cup)
10. Potato (1)
11. Raspberries (1 cup)
12. Rice - Brown (1 cup)
13. Rice - White (1 cup)
14. Strawberries (.5 cup)
15. Steak (8 ozs)

Enter your selection or X to exit: 12
Now enter the number of servings: 1

You selected 1.0 servings of brown rice.

Please select from the following list of foods:

1. Apple (1)
2. Beans (1 cup)
3. Bread - White (1 slice)
4. Bread - Whole Wheat (1 slice)
5. Burger (1)
6. Carrot (1 medium)
7. Chicken (8 oz)
8. Egg (1)
9. Pasta (1 cup)
10. Potato (1)
11. Raspberries (1 cup)
12. Rice - Brown (1 cup)
13. Rice - White (1 cup)
14. Strawberries (.5 cup)
15. Steak (8 ozs)

Enter your selection or X to exit: 2
Now enter the number of servings: 1

You selected 1.0 servings of beans.

Please select from the following list of foods:

1. Apple (1)
2. Beans (1 cup)
3. Bread - White (1 slice)
4. Bread - Whole Wheat (1 slice)
5. Burger (1)
6. Carrot (1 medium)
7. Chicken (8 oz)
8. Egg (1)
9. Pasta (1 cup)
10. Potato (1)
11. Raspberries (1 cup)
12. Rice - Brown (1 cup)
13. Rice - White (1 cup)
14. Strawberries (.5 cup)
15. Steak (8 ozs)

Enter your selection or X to exit: 1
Now enter the number of servings: 1

You selected 1.0 servings of apple.

Please select from the following list of foods:

1. Apple (1)
2. Beans (1 cup)
3. Bread - White (1 slice)
4. Bread - Whole Wheat (1 slice)
5. Burger (1)
6. Carrot (1 medium)
7. Chicken (8 oz)
8. Egg (1)
9. Pasta (1 cup)
10. Potato (1)
11. Raspberries (1 cup)
12. Rice - Brown (1 cup)
13. Rice - White (1 cup)
14. Strawberries (.5 cup)
15. Steak (8 ozs)

Enter your selection or X to exit: 9
Now enter the number of servings: 2

You selected 2.0 servings of pasta.

Please select from the following list of foods:

1. Apple (1)
2. Beans (1 cup)
3. Bread - White (1 slice)
4. Bread - Whole Wheat (1 slice)
5. Burger (1)
6. Carrot (1 medium)
7. Chicken (8 oz)
8. Egg (1)
9. Pasta (1 cup)
10. Potato (1)
11. Raspberries (1 cup)
12. Rice - Brown (1 cup)
13. Rice - White (1 cup)
14. Strawberries (.5 cup)
15. Steak (8 ozs)

Enter your selection or X to exit: 6
Now enter the number of servings: 1.5

You selected 1.5 servings of carrot.

Please select from the following list of foods:

1. Apple (1)
2. Beans (1 cup)
3. Bread - White (1 slice)
4. Bread - Whole Wheat (1 slice)
5. Burger (1)
6. Carrot (1 medium)
7. Chicken (8 oz)
8. Egg (1)
9. Pasta (1 cup)
10. Potato (1)
11. Raspberries (1 cup)
12. Rice - Brown (1 cup)
13. Rice - White (1 cup)
14. Strawberries (.5 cup)
15. Steak (8 ozs)

Enter your selection or X to exit: 10
Now enter the number of servings: 1

You selected 1.0 servings of potato.

Please select from the following list of foods:

1. Apple (1)
2. Beans (1 cup)
3. Bread - White (1 slice)
4. Bread - Whole Wheat (1 slice)
5. Burger (1)
6. Carrot (1 medium)
7. Chicken (8 oz)
8. Egg (1)
9. Pasta (1 cup)
10. Potato (1)
11. Raspberries (1 cup)
12. Rice - Brown (1 cup)
13. Rice - White (1 cup)
14. Strawberries (.5 cup)
15. Steak (8 ozs)

Enter your selection or X to exit: X
Now enter today's date: May 22, 2020

Here is your fiber summary for May 22, 2020:

Total grams consumed: 45.0
You're a fiber superstar! Keep up the good work!



Sample output:

Welcome to the fiber counter!
Let's calculate your daily fiber consumption for the day.

Please select from the following list of foods:

1. Apple (1)
2. Beans (1 cup)
3. Bread - White (1 slice)
4. Bread - Whole Wheat (1 slice)
5. Burger (1)
6. Carrot (1 medium)
7. Chicken (8 oz)
8. Egg (1)
9. Pasta (1 cup)
10. Potato (1)
11. Raspberries (1 cup)
12. Rice - Brown (1 cup)
13. Rice - White (1 cup)
14. Strawberries (.5 cup)
15. Steak (8 ozs)

Enter your selection or X to exit: 4
Now enter the number of servings: 2

You selected 2.0 servings of whole wheat bread.

Please select from the following list of foods:

1. Apple (1)
2. Beans (1 cup)
3. Bread - White (1 slice)
4. Bread - Whole Wheat (1 slice)
5. Burger (1)
6. Carrot (1 medium)
7. Chicken (8 oz)
8. Egg (1)
9. Pasta (1 cup)
10. Potato (1)
11. Raspberries (1 cup)
12. Rice - Brown (1 cup)
13. Rice - White (1 cup)
14. Strawberries (.5 cup)
15. Steak (8 ozs)

Enter your selection or X to exit: 8
Now enter the number of servings: 1

You selected 1.0 servings of egg.

Please select from the following list of foods:

1. Apple (1)
2. Beans (1 cup)
3. Bread - White (1 slice)
4. Bread - Whole Wheat (1 slice)
5. Burger (1)
6. Carrot (1 medium)
7. Chicken (8 oz)
8. Egg (1)
9. Pasta (1 cup)
10. Potato (1)
11. Raspberries (1 cup)
12. Rice - Brown (1 cup)
13. Rice - White (1 cup)
14. Strawberries (.5 cup)
15. Steak (8 ozs)

Enter your selection or X to exit: 11
Now enter the number of servings: 1

You selected 1.0 servings of raspberries.

Please select from the following list of foods:

1. Apple (1)
2. Beans (1 cup)
3. Bread - White (1 slice)
4. Bread - Whole Wheat (1 slice)
5. Burger (1)
6. Carrot (1 medium)
7. Chicken (8 oz)
8. Egg (1)
9. Pasta (1 cup)
10. Potato (1)
11. Raspberries (1 cup)
12. Rice - Brown (1 cup)
13. Rice - White (1 cup)
14. Strawberries (.5 cup)
15. Steak (8 ozs)

Enter your selection or X to exit: 9
Now enter the number of servings: 1.5

You selected 1.5 servings of pasta.

Please select from the following list of foods:

1. Apple (1)
2. Beans (1 cup)
3. Bread - White (1 slice)
4. Bread - Whole Wheat (1 slice)
5. Burger (1)
6. Carrot (1 medium)
7. Chicken (8 oz)
8. Egg (1)
9. Pasta (1 cup)
10. Potato (1)
11. Raspberries (1 cup)
12. Rice - Brown (1 cup)
13. Rice - White (1 cup)
14. Strawberries (.5 cup)
15. Steak (8 ozs)

Enter your selection or X to exit: 1
Now enter the number of servings: 1

You selected 1.0 servings of apple.

Please select from the following list of foods:

1. Apple (1)
2. Beans (1 cup)
3. Bread - White (1 slice)
4. Bread - Whole Wheat (1 slice)
5. Burger (1)
6. Carrot (1 medium)
7. Chicken (8 oz)
8. Egg (1)
9. Pasta (1 cup)
10. Potato (1)
11. Raspberries (1 cup)
12. Rice - Brown (1 cup)
13. Rice - White (1 cup)
14. Strawberries (.5 cup)
15. Steak (8 ozs)

Enter your selection or X to exit: 7
Now enter the number of servings: 1.5

You selected 1.5 servings of chicken.

Please select from the following list of foods:

1. Apple (1)
2. Beans (1 cup)
3. Bread - White (1 slice)
4. Bread - Whole Wheat (1 slice)
5. Burger (1)
6. Carrot (1 medium)
7. Chicken (8 oz)
8. Egg (1)
9. Pasta (1 cup)
10. Potato (1)
11. Raspberries (1 cup)
12. Rice - Brown (1 cup)
13. Rice - White (1 cup)
14. Strawberries (.5 cup)
15. Steak (8 ozs)

Enter your selection or X to exit: 12
Now enter the number of servings: 1

You selected 1.0 servings of brown rice.

Please select from the following list of foods:

1. Apple (1)
2. Beans (1 cup)
3. Bread - White (1 slice)
4. Bread - Whole Wheat (1 slice)
5. Burger (1)
6. Carrot (1 medium)
7. Chicken (8 oz)
8. Egg (1)
9. Pasta (1 cup)
10. Potato (1)
11. Raspberries (1 cup)
12. Rice - Brown (1 cup)
13. Rice - White (1 cup)
14. Strawberries (.5 cup)
15. Steak (8 ozs)

Enter your selection or X to exit: 10
Now enter the number of servings: 1

You selected 1.0 servings of potato.

Please select from the following list of foods:

1. Apple (1)
2. Beans (1 cup)
3. Bread - White (1 slice)
4. Bread - Whole Wheat (1 slice)
5. Burger (1)
6. Carrot (1 medium)
7. Chicken (8 oz)
8. Egg (1)
9. Pasta (1 cup)
10. Potato (1)
11. Raspberries (1 cup)
12. Rice - Brown (1 cup)
13. Rice - White (1 cup)
14. Strawberries (.5 cup)
15. Steak (8 ozs)

Enter your selection or X to exit: x
Now enter today's date: May 22, 2020

Here is your fiber summary for May 22, 2020:

Total grams consumed: 24.5
You eat the average amount of daily fiber for an American.
You need to increase your intake to at least 30 grams/day.