Sunday 29 September 2013

if/else with char type

if/else with char type

Pleas help. Hi so iv'e been working on my lab all day and haven't found a
way to accomplish what is being asked. Below is the requirements.
Input Data:
Use Scanner methods to enter Either "M" for a man or "W" for a woman.
weight, height, and age at the keyboard. Use a named constant for the
number of calories in a "typical chocolate bar." Processing:
Using the same input data, Set up the equations to calculate the basal
metabolic rate: WBMR (basal metabolic rate for a woman) MBMR (basal
metabolic rate for a man) Calculate number of chocolate bars consumed to
maintain one's weight by a man woman Output Data:
Display the following items, one per line, each along with an appropriate
message: weight height age if "W" entered, WBMR (basal metabolic rate for
a woman), the number of chocolate bars a woman would need to consume to
maintain her weight. if "M" entered, MBMR (basal metabolic rate for a
man), the number of chocolate bars a man would need to consume to maintain
his weight. Extra-credit (5 points), if you format your last 4 output
items with 2 digits after the decimal point Refer to the optional section
on formatting output in chapter 2.
And below this is my script so far.
` /*This program calculates the BMR of a woman and man. Also it
*calculates how many chocolate bars is needed to maintain your BMR.
*Shayan Nick Raissian *shayanraissian@gmail.com *09/17/13 */
import java.util.Scanner;
public class HarrisBenedict3
{
public static void main(String[] args)
{
/**
*wBmr = Woman basal metabolic rate
*mBmr = Men basal metabolic rate
*nCbw = Number of chocolate bars for men
*nCbm = Number of chocolate bars for women
*/
double weight, height, age, wBmr, mBmr, nCbw, nCbm;
char gender;
/*In this section I am having the user input the variables
*using the keyboard.
*/
Scanner keyboard = new Scanner(System.in);
System.out.println("Hello");
System.out.println("Today we are going to estimate the number of
calories your body needs to\nmaintain your weight if you don't
exercise");
System.out.println("The term used for this calculation is called basal
metabolic rate, or BMR");
System.out.println("First thing I need you to do is input your weight
in pounds");
weight = keyboard.nextDouble();
System.out.println("Next input your height in inches");
height = keyboard.nextDouble();
System.out.println("Last step is to input your age");
age = keyboard.nextDouble();
/*This section includes the formulas needed to compute a
*the two BMRs.
*/
wBmr = 655 + (4.3 * weight) + (4.7 * height) - ( 4.7 * age);
mBmr = 66 + (6.3 * weight) + (12.9 * height) - (6.8 * age);
gender = keyboard.nextChar();
if (gender == 'w') {
System.out.printf("If you're a woman then your BMR is " +
"%.2f%n", wBmr);
}
else {
System.out.printf("If you're a man then your BMR is " + "%.2f%n",
mBmr);
}
/*This section includes the outputs of the SBMR formulas. Also I include
*the extra credit portion so that there is only two numbers past the
decimal point.
*/
System.out.println("Now we are going to calculate your BMR");
System.out.println("Beep Boop Bop");
System.out.printf("If you're a woman then your BMR is " + "%.2f%n",
wBmr);
System.out.printf("If you're a man then your BMR is " + "%.2f%n", mBmr);
/*This section includes the formula for calculating the number
*chocolate bars needed to maintain one's weight.
*/
nCbw = wBmr / 230;
nCbm = mBmr / 230;
/*This section includes the output's for the chocolate bar
*calculations. Also I include the extra credit portion so that there
is only
*two numbers past the decimal point.
*/
System.out.println("Now we are going calculate how many chocolate bars
are needed to maintain one's\nweight");
System.out.printf("If you're a woman then you need " + "%.2f%n", nCbm);
System.out.println("chocolates to maintain your weight");
System.out.printf("If you're a man then you need " + "%.2f%n", nCbm);
System.out.println("chocolates to maintain your weight");
System.out.println("Thank you, and Good Bye.");
}
} `
PLEASE HELP.

No comments:

Post a Comment