Question

In: Computer Science

Decision Structures Calorie Calculator Assignment Overview This assignment will give you practice with numerical calculations, simple...

Decision Structures Calorie Calculator Assignment Overview This assignment will give you practice with numerical calculations, simple input/output, and if-else statements. Program Objective: In this exercise, you will write a program the calculates the Daily Caloric needs for weight lose diet. According to everydayhealth.com they recommend this daily caloric formula for a weight loss diet: BMR + Activity Level - 500 calories. Calories Calculator The Harris-Benedict equation estimates the number of calories your body needs to maintain your weight if you do no exercise. This is called your basal metabolic rate or BMR. The Calories needed for a woman to maintain her weight is: BMR = 655 + (4.3 * weight in pounds) + (4.7 * height in inches) - (4.7 * age in years) The Calories needed for a man to maintain his weight is: BMR = 66 + (6.3 * weight in pounds) + (12.9 * height in inches) - (6.8 * age in years) Next, the total daily caloric requirement is calculated by multiplying your BMR by your level of activity: • If the person is inactive (rarely exercise), then increase the calculated BMR 20%. • If the person is somewhat active, then increase the calculated BMR by 30% • If the person is active, then increase the calculated BMR by 40% • If the person is highly active then increase the calculated BMR by 50% Program Specification: Write a program that allows the user to input their weight in pounds, height in inches, and age in years. Ask the user to input the string “M” if the user is a man and “W” if the user is a woman. Use only the male formula to calculate calories if “M” is entered and use only the women formula to calculate calories if “W” is entered. Ask the user if he or she is: A. Inactive B. Somewhat active (exercise occasionally) C. Active (exercise 3-4 days per week) D. Highly active (exercise every day) • If the user answers “Inactive” then increase the calculated BMR by 20 percent. • If the user answers “Somewhat active” then increase the calculated BMR by 30 percent. • If the user answers “Active” then increase the calculated BMR by 40 percent. • Finally, if the user answers “Highly active” then increase the calculated BMR by 50 percent. • The program should then output the calculated daily Calories intake for this person in order to lose one pound per week by subtracting 500 calories from the calculated BMR. Input Errors • If the user enters an age either < 1 or > 100, instantly end the program with an error message. • If the user enters a height < 10 or > 100, instantly end the program with an error message. • If the user enters a weight < 10 or > 500, instantly end the program with an error message. • You can assume that the user does not type some non-numeric value. You don't have to test for this kind of non-numeric error. • If the user does not enter ‘M' for male calculation or 'W' for female calculation, instantly end the program with an error message. • If the user does not enter A, B, C, or D when prompted, instantly end the program with an error message. These limits must be defined as symbolic constants, which should be used throughout the program. Rules: • For this assignment you are limited to the Java features in Chapters 1 through 3; you are not allowed to use more advanced features to solve the problem. Please do not use Java features that are not covered in lecture or the textbook. • Use class constants as appropriate to represent important fixed data values in your program. • Follow programming guidelines and Java’s naming standards about the format of ClassNames, variableNames, and CONSTANT NAMES. • Notice that all real numbers output by the program are printed with no more than 2 digits after the decimal point. To achieve this, you may use the System.out.printf method. • Add the header to the class file and copy/paste the output that is produced by your program into the bottom of the source code file, making it into a block comment. • Class Name: Your program class should be called CalorieCalculator.

Solutions

Expert Solution

/*********************************CalorieCalculator.java****************************/

import java.util.Scanner;

/**
* The Class CalorieCalculator.
*/
public class CalorieCalculator {

   /**
   * The main method.
   *
   * @param args the arguments
   */
   public static void main(String[] args) {

       Scanner scan = new Scanner(System.in);
       char option;
      
       do {
           double bmr = 0;
           System.out.print("Input Weight in pounds: ");
           double weight = scan.nextDouble();
           if (weight < 10 || weight > 500) {
               System.out.println("Invalid Weight!");
               break;
           }
           System.out.print("Input Height in inches: ");
           double height = scan.nextDouble();
           if (height < 10 || height > 100) {

               System.out.println("Invalid Height!");
               break;
           }
           System.out.print("Input Age in years: ");
           int age = scan.nextInt();
           if (age < 1 || age > 100) {

               System.out.println("Invalid age!");
               break;
           }
           scan.nextLine();
           System.out.print("Enter Gender: ");
           char gender = scan.nextLine().toUpperCase().charAt(0);
           if (gender == 'M') {
               bmr = 655 + (6.3 * weight) + (12.9 * height) - (6.8 * age);
              
           } else if (gender == 'W') {

               bmr = 655 + (4.3 * weight) + (4.7 * height) - (4.7 * age);
           }
           menu();
           System.out.print("Which Type of person you are: ");
           String type = scan.nextLine();
           if (type.equalsIgnoreCase("a")) {

               bmr+=bmr * .20;
           } else if (type.equalsIgnoreCase("b")) {

               bmr += bmr *.30;
           } else if (type.equalsIgnoreCase("c")) {

               bmr += bmr * .40;
           } else if (type.equalsIgnoreCase("d")) {

               bmr += bmr * .50;
           }

           System.out.printf("Daily Caloric needs for weight lose diet: %.2f Calories\n", (bmr - 500));

           System.out.println("Do you want to continue(Y/N): ");
           option = scan.nextLine().toUpperCase().charAt(0);

       } while (option != 'N');
   }

   /**
   * Menu.
   */
   private static void menu() {

       System.out.println("A. Inactive \n" + "B. Somewhat active (exercise occasionally) \n"
               + "C. Active (exercise 3-4 days per week) \n" + "D. Highly active (exercise every day)");

   }
}
/****************output******************/

Input Weight in pounds: 100
Input Height in inches: 70
Input Age in years: 30
Enter Gender: M
A. Inactive
B. Somewhat active (exercise occasionally)
C. Active (exercise 3-4 days per week)
D. Highly active (exercise every day)
Which Type of person you are: B
Daily Caloric needs for weight lose diet: 2079.20 Calories
Do you want to continue(Y/N):
Y
Input Weight in pounds: 200
Input Height in inches: 78
Input Age in years: 25
Enter Gender: W
A. Inactive
B. Somewhat active (exercise occasionally)
C. Active (exercise 3-4 days per week)
D. Highly active (exercise every day)
Which Type of person you are: C
Daily Caloric needs for weight lose diet: 1969.74 Calories
Do you want to continue(Y/N):
N

Please let me know if you have any doubt or modify the answer, Thanks :)


Related Solutions

Assignment Overview IN C++ This assignment will give you practice with numerical calculations, simple input/output, and...
Assignment Overview IN C++ This assignment will give you practice with numerical calculations, simple input/output, and if-else statements. Candy Calculator [50 points] The Harris-Benedict equation estimates the number of calories your body needs to maintain your weight if you do no exercise. This is called your basal metabolic rate or BMR. The calories needed for a woman to maintain her weight is: BMR = 655 + (4.3 * weight in pounds) + (4.7 * height in inches) - (4.7 *...
Assignment Overview This assignment will give you practice with interactive programs and if/else statements. Part 1:...
Assignment Overview This assignment will give you practice with interactive programs and if/else statements. Part 1: User name Generator Write a program that prompts for and reads the user’s first and last name (separately). Then print a string composed of the first letter of the user’s first name, followed by the first five characters of the user’s last name, followed by a random number in the range 10 to 99. Assume that the last name is at least five letters...
Python code Assignment Overview In this assignment you will practice with conditionals and loops (for). This...
Python code Assignment Overview In this assignment you will practice with conditionals and loops (for). This assignment will give you experience on the use of the while loop and the for loop. You will use both selection (if) and repetition (while, for) in this assignment. Write a program that calculates the balance of a savings account at the end of a period of time. It should ask the user for the annual interest rate, the starting balance, and the number...
For this assignment you will develop pseudocode and write a C++ program for a simple calculator....
For this assignment you will develop pseudocode and write a C++ program for a simple calculator. You will create both files in Codio. Put your pseudocode and C++ code in the files below. PSEUDOCODE FILE NAME: Calculator.txt C++ SOURCE CODE FILE NAME : Calculator.cpp DESCRIPTION: Write a menu-driven program to perform arithmetic operations and computations on a list of integer input values. Present the user with the following menu. The user will choose a menu option. The program will prompt...
Programming Assignment #3: SimpleFigure and CirclesProgram Description:This assignment will give you practice with value...
Programming Assignment #3: SimpleFigure and CirclesProgram Description:This assignment will give you practice with value parameters, using Java objects, and graphics. This assignment has 2 parts; therefore you should turn in two Java files.You will be using a special class called DrawingPanel written by the instructor, and classes called Graphics and Color that are part of the Java class libraries.Part 1 of 2 (4 points)Simple Figure, or your own drawingFor the first part of this assignment, turn in a file named...
For this assignment we're going to make another calculator. This one will be a simple four...
For this assignment we're going to make another calculator. This one will be a simple four function (add, subtract, multiply, and divide) calculator, but it will have state. Specifically, the calculator will keep track of the result of the most recent operation and use that value as the first operand for the next operation. Take a look at the sample output below if this doesn't quite make sense. Your new calculator class should have the following fields and methods: fields:...
Java For this project, we want to build a calculator program that can perform simple calculations...
Java For this project, we want to build a calculator program that can perform simple calculations and provide an output. If it encounters any errors, it should print a helpful error message giving the nature of the error. You may use any combination of If-Then statements and Try-Catch statements to detect and handle errors. Program Specification Input Our program should accept input in one of two ways: If a command-line argument is provided, it should read input from the file...
This problem will give you hands-on practice with the following programming concepts: • All programming structures...
This problem will give you hands-on practice with the following programming concepts: • All programming structures (Sequential, Decision, and Repetition) • Methods • Random Number Generation (RNG) Create a Java program that teaches people how to multiply single-digit numbers. Your program will generate two random single-digit numbers and wrap them into a multiplication question. The program will provide random feedback messages. The random questions keep generated until the user exits the program by typing (-1). For this problem, multiple methods...
Assignment 1: Analyzing an Ethical Decision In your role, as an advanced practice nurse, you will...
Assignment 1: Analyzing an Ethical Decision In your role, as an advanced practice nurse, you will encounter several situations that will require your ability to make sound judgments and practice decisions for the safety and well-being of individuals, families, and communities. There may not be a clear cut answer of how to address the issue, but your ethical decision making must be based on evidenced based practice, and what is good, right, and beneficial for patients. You will encounter patients...
Assignment 1: Analyzing an Ethical Decision In your role, as an advanced practice nurse, you will...
Assignment 1: Analyzing an Ethical Decision In your role, as an advanced practice nurse, you will encounter several situations that will require your ability to make sound judgments and practice decisions for the safety and well-being of individuals, families, and communities. There may not be a clear cut answer of how to address the issue, but your ethical decision making must be based on evidenced based practice, and what is good, right, and beneficial for patients. You will encounter patients...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT