Question

In: Computer Science

JAVA CODE BEGINNER , Please use comments to explain, please Repeat the calorie-counting program described in...

JAVA CODE BEGINNER , Please use comments to explain, please

Repeat the calorie-counting program described in Programming Project 8 from Chapter 2. This time 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 female formula to calculate calories if “W” is entered. Output the number of chocolate bars to consume as before.

and this project 8:

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)

A typical chocolate bar will contain around 230 calories. Write a program that allows the user to input his or her weight in pounds, height in inches, and age in years. The program should then output the number of chocolate bars that should be consumed to maintain one’s weight for both a woman and a man of the input weight, height, and age.

Solutions

Expert Solution

Java Code :

import java.util.Scanner;           // for using Scanner class
public class Solution
{
    public static void main(String args[])
    {
        Scanner obj = new Scanner(System.in);           // Creating Scanner class object
      
       System.out.print("\nInput the String : ");           // Asking for the input of the String
        String s = obj.next();               // taking input of String
      
       System.out.println();
      
       double BMR = 0.0;           // it will store the value of BMR
        if(s.equals("W"))           // if the input String is "W", then we'll go with Woman
        {
            System.out.print("\nEnter the weight in pounds for woman : ");           // Asking for the input of weight in pounds for woman
            double weight = obj.nextDouble();               // taking input of weight in pounds for woman
            System.out.print("\nEnter the height in inches for woman : ");           // Asking for the input of height in inches for woman
            int height = obj.nextInt();               // taking input of height in inches for woman
            System.out.print("\nEnter the age in years for woman : ");           // Asking for the input of age in years for woman
            int age = obj.nextInt();               // taking input of age in years for woman
          
            BMR = 655 + (4.3 * weight) + (4.7 * height) - (4.7 * age);           // Calculating BMR for woman
        }
        else if(s.equals("M"))           // if the input String is "M", then we'll go with Man
        {
            System.out.print("\nEnter the weight in pounds for man : ");           // Asking for the input of weight in pounds for man
            double weight = obj.nextDouble();               // taking input of weight in pounds for man
            System.out.print("\nEnter the height in inches for man : ");           // Asking for the input of height in inches for man
            int height = obj.nextInt();               // taking input of height in inches for man
            System.out.print("\nEnter the age in years for man : ");           // Asking for the input of age in years for man
            int age = obj.nextInt();               // taking input of age in years for man
          
            BMR = 66 + (6.3 * weight) + (12.9 * height) - (6.8 * age);           // Calculating BMR for man
        }
      
        double choc = BMR / 230.0;               // Calculating number of chocolate bars required
        int chocolates = Math.round((float)choc);       // Rounding off the double value of number of chocolate bars required for getting exact number of chocolates
      
        System.out.print("\n\nThe number of chocolate bars that should be consumed : " + chocolates + "\n\n" );           // printing number of chocolate bars
    }
}

Java Code Output :


Related Solutions

JAVA CODE, BEGINERS; Please use comments to explain For all of the following words, if you...
JAVA CODE, BEGINERS; Please use comments to explain For all of the following words, if you move the first letter to the end of the word, and then spell the result backwards, you will get the original word: banana dresser grammar potato revive uneven assess Write a program that reads a word and determines whether it has this property. Continue reading and testing words until you encounter the word quit. Treat uppercase letters as lowercase letters.
JAVA CODE, USE COMMENTS TO EXPLAIN PLEASE Write a Bottle class. The Bottle will have one...
JAVA CODE, USE COMMENTS TO EXPLAIN PLEASE Write a Bottle class. The Bottle will have one private int that represents the countable value in the Bottle. Please use one of these names: cookies, marbles, M&Ms, pennies, nickels, dimes or pebbles. The class has these 14 methods: read()(please use a while loop to prompt for an acceptable value), set(int), set(Bottle), get(), (returns the value stored in Bottle), add(Bottle), subtract(Bottle), multiply(Bottle), divide(Bottle), add(int), subtract(int), multiply(int), divide(int), equals(Bottle), and toString()(toString() method will be...
Please use Java language with comments! Thanks! Write a program that will display multiple dots move...
Please use Java language with comments! Thanks! Write a program that will display multiple dots move across the Frame and randomly change direction when they hit the edge of the screen. Do this by creating a Dot class and making each dot an object of that class. You may reuse code written in class for this part of the assignment. Create a subclass of the Dot class called PlayerDot that is controlled by the player through keyboard input (arrow keys)...
Please use java language in an easy way with comments! Expand your below program, so it...
Please use java language in an easy way with comments! Expand your below program, so it can include cursed items (weapons that break, armor that causes more damage when worn). In order to do that, write an interface called "CursedItem". Then create subclasses of the armor, and weapon class that implement the CursedItem interface : CursedWeapon: using a random number generator, there is a 4 in 10 chance that the weapon breaks during combat. CursedArmor: this item amplifies the damage...
write this program in java... don't forget to put comments. You are writing code for a...
write this program in java... don't forget to put comments. You are writing code for a calendar app, and need to determine the end time of a meeting. Write a method that takes a String for a time in H:MM or HH:MM format (the program must accept times that look like 9:21, 10:52, and 09:35) and prints the time 25 minutes later. For example, if the user enters 9:21 the method should output 9:46 and if the user enters 10:52...
Hello, Please write this program in java and include a lot of comments and please try...
Hello, Please write this program in java and include a lot of comments and please try to make it as simple/descriptive as possible since I am also learning how to code. The instructions the professor gave was: Create your own class Your own class can be anything you want Must have 3 instance variables 1 constructor variable → set the instance variables 1 method that does something useful in relation to the class Create a driver class that creates an...
Please write in beginner level PYTHON code! Your job is to write a Python program that...
Please write in beginner level PYTHON code! Your job is to write a Python program that asks the user to make one of two choices: destruct or construct. - If the user chooses to destruct, prompt them for an alternade, and then output the 2 words from that alternade. - If the user chooses construct, prompt them for 2 words, and then output the alternade that would have produced those words. - You must enforce that the users enter real...
Please show solution and comments for this data structure using java.​ Implement a program in Java...
Please show solution and comments for this data structure using java.​ Implement a program in Java to convert an infix expression that includes (, ), +, -, *,     and / to postfix expression. For simplicity, your program will read from standard input (until the user enters the symbol “=”) an infix expression of single lower case and the operators +, -, /, *, and ( ), and output a postfix expression.
Please add comments to this code! JAVA Code: import java.text.NumberFormat; public class Item {    private...
Please add comments to this code! JAVA Code: import java.text.NumberFormat; public class Item {    private String name;    private double price;    private int bulkQuantity;    private double bulkPrice;    /***    *    * @param name    * @param price    * @param bulkQuantity    * @param bulkPrice    */    public Item(String name, double price, int bulkQuantity, double bulkPrice) {        this.name = name;        this.price = price;        this.bulkQuantity = bulkQuantity;        this.bulkPrice = bulkPrice;   ...
JAVA PROGRAM: INCLUDE COMMENTS EXPLAINING THE CODE PLEASE Given the following information: 13-inch MacBook Air, 1.6GHz...
JAVA PROGRAM: INCLUDE COMMENTS EXPLAINING THE CODE PLEASE Given the following information: 13-inch MacBook Air, 1.6GHz dual-core Intel Core i5 processor, Turbo Boost up to 2.7GHz, Intel HD Graphics 6000, 8GB memory, 128GB PCIe-based flash storage 13-inch MacBook Air, 1.6GHz dual-core Intel Core i5 processor, Turbo Boost up to 2.7GHz, Intel HD Graphics 6000, 8GB memory, 256GB PCIe-based flash storage 15.6-inch Dell i3552, 1.6GHz Processor, Intel Pentium N3700, HD Laptop, 4 GB memory, DDR3L SDRAM, Windows 10, Black Drive 3...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT