UPDATED AS FIXES ARE POSTED
Issue I'm having now is getting the displayResults method to call in weight height and gender for the calculations. Also I have one other issue where I need the user inputs to ignore what case the response is in.
import java.util.Scanner;
public class myHealthCalculator
{
public static void main(String[] args)
{
displayPurpose();
//create person object
myPerson person = new myPerson();
Scanner keyboard = new Scanner( System.in );
System.out.print("Please enter weight in pounds: ");
person.weight = keyboard.nextDouble();
System.out.print("Please enter height in inches: ");
person.height = keyboard.nextDouble();
System.out.print("Please enter your age in years: ");
person.age = keyboard.nextInt();
System.out.print("Please enter your gender (M/F): ");
person.gender = (char) keyboard.nextDouble();
person.bodyMassIndex(0, 0);
person.calorieComp(0, 0, 0);
displayResults(person.bodyMassIndex(0, 0),person.calorieComp(0, 0, 0));
}
public static void displayPurpose()
{
System.out.println("This program implements a Health Assistance "
+ "Calculator");
System.out.println("\nGiven a weight, height, and age, it will compute:");
System.out.println(" BMI - Body Mass Index");
System.out.println(" Calories needed per day to maintain weight");
System.out.println();
}
public static void displayResults(double resultBMI, int calCompu)
{
Scanner keyboard2 = new Scanner( System.in );
final double LOW_N_BMI = 18.5;
final double HI_N_BMI = 24.9;
System.out.println("\n");
System.out.printf("%nA BMI in the range of " + LOW_N_BMI + " to "
+ HI_N_BMI + " is considered normal" );
//getters here, gender, age, weight kgs and height meters.
System.out.printf("Current weight in kgs is: " + "%.2f", weight);
System.out.printf("Current height in meteres: " + "%.3f", height);
if (gender == 'm')
System.out.println("Gender is: " + "Male");
else
System.out.println("Gender is: " + "Female");
System.out.printf("Your BMI is: " + "%.1f", resultBMI);
if (resultBMI < LOW_N_BMI)
System.out.println("BMI is below normal");
else if (resultBMI > HI_N_BMI)
System.out.println("BMI is above normal");
else
System.out.println("BMI is normal");
System.out.printf("%nTo maintain your current weight, you should consume ", calCompu, "calories per day.");
if (resultBMI < LOW_N_BMI)
{
System.out.println("Would you like to try and reach the normal range? ");
String questionOne = keyboard2.next();
if (questionOne == "y")
{
System.out.println("how many pounds would you like to gain per week? ");
double questionTwo = keyboard2.nextDouble();
double gainRate = questionTwo * 3500;
System.out.println(" To gain " + questionTwo + " pound(s) per "
+ "week, you should consume " + gainRate + "Calories per day.");
}
else
{
}
}
else if (resultBMI > HI_N_BMI)
{
System.out.println("Would you like to try and reach the normal range? ");
double questionThree = keyboard2.nextDouble();
double loseRate = questionThree / 3500;
System.out.println(" To lose " + questionThree + " pound(s) per "
+ "week, you should consume " + loseRate + "Calories per day.");
}
else
{
}
}
}
and the other class
import java.util.Scanner;
public class myPerson
{
// data fields
double weight = 0;
double height = 0;
int age = 0;
double gender = ' '; //char 'M' or 'F'
private double resultBMI = 0;
//person constructor
public myPerson ()
{
//conversion factors for metric (need to convert input
//which will be in imperial messurements)
final double KG_WEIGHT_CONV = 2.2;
final double MT_HEIGHT_CONV = 0.0254;
double calCopu = 0.0;
}
public void setWeight (double weight, double KG_WEIGHT_CONV) {
this.weight = weight / KG_WEIGHT_CONV;
}
public void setHeight (double height, double MT_HEIGHT_CONV) {
this.height = height * MT_HEIGHT_CONV;
}
public void setAge (int age) {
this.age = age;
}
public void setGender (double gender) {
this.gender = gender;
}
public double getWeight () {
return weight;
}
public double getHeight () {
return height;
}
public int getAge () {
return age;
}
public double getGender () {
return gender;
}
//instance method to calculate BMI
public double bodyMassIndex(double weightKgs, double heightMeters)
{
/**
* Compute a person's BMI, will return a double value
* squares the height using the pow method from java.Math.
*/
return (weightKgs / Math.pow(heightMeters, 2));
}
public int calorieComp(double weightInKg, double heightInMeters, int ageInYears)
{
double heightInCentimeters = heightInMeters * 100;
System.out.println("Select your activity level: ");
System.out.println(" 1 - Sedentary");
System.out.println(" 2 - Moderately active (light exercise 1-3 days a week) ");
System.out.println(" 3 - Active (moderate exercise 3-5 days a week) ");
System.out.println(" 4 - Very active (heavy exercise 6-7 days a week) ");
System.out.printf("Enter choice from above: ");
char aFactor;
Scanner keyboard = new Scanner(System.in);
aFactor = keyboard.next().charAt(0);
switch (aFactor)
{
case '1':
aFactor = (char) 1.2; //Sedentary people
break;
case '2':
aFactor = (char) 1.375; //Moderate active people
break;
case '3':
aFactor = (char) 1.55; //Active people
break;
case '4':
aFactor = (char) 1.725; //Very active people
break;
default :
System.out.println("Invalid choice entered!");
}
if (gender == 'm')
{
//return men
double basalMetabolicRate = 13.397 * weightInKg + 4.799
* heightInCentimeters - 5.677 * ageInYears + 88.362;
double psyActFact = basalMetabolicRate * aFactor;
int calCompu = (int) Math.ceil(psyActFact);
return calCompu;
}
else
{
//return women
double basalMetabolicRate = 9.247 * weightInKg + 3.098
* heightInCentimeters - 4.330 * ageInYears + 447.593;
double psyActFact = basalMetabolicRate * aFactor;
int calCompu = (int) Math.ceil(psyActFact);
return calCompu;
}
}
}