The program basically ask user to input their BMR, and gender. Then they're ask to choose an activity level ( If they choose the wrong one, I need to print" Please enter a valid choice"). Female and male have different activity factor. I'm encountering an error of " Variable ActivityFactor must be initialized." How can I fix my code? Thanks
iBMR = new Scanner(System.in);
Scanner iGender = new Scanner(System.in);
Scanner iActivity = new Scanner(System.in);
String AcFactor;
double ActivityFactor ;
double TDEE;
//User Input
System.out.println("Please enter your name: ");
String inName = iName.next();
System.out.println("Please enter your BMR: ");
String inBMR = iBMR.next();
double nBMR = Double.parseDouble(inBMR);
System.out.println("Please enter your Gender");
String inGender = iGender.next();
System.out.println("Select Your Activity Level");
System.out.println("[A] Resting (Sleeping,Reclining)");
System.out.println("[B] Sedentary (Minimal Movement)");
System.out.println("[C] Light (Sitting, Standing)");
System.out.println("[D] Moderate (Light Manual Labor, Dancing, Riding Bike)");
System.out.println("[E] Very Active (Team Sports, Hard Manual Labor)");
System.out.println("[F] Extremely Active (Full-time Athlete, Heavy Manual Labor)");
System.out.println("Enter the letter corrresponding to your activity level: ");
String inActivity = iActivity.next();
//CalculationFemale
if(inActivity.equalsIgnoreCase("A")&& inGender.equalsIgnoreCase("F"))
{
ActivityFactor = 1.0;
}
else if(inActivity.equalsIgnoreCase("B")&& inGender.equalsIgnoreCase("F"))
{
ActivityFactor = 1.3;
}
else if(inActivity.equalsIgnoreCase("C")&& inGender.equalsIgnoreCase("F"))
{
ActivityFactor = 1.5;
}
else if(inActivity.equalsIgnoreCase("D")) && (inGender.equalsIgnoreCase("F"))
{
ActivityFactor = 1.6;
}
else if(inActivity.equalsIgnoreCase("E")&& inGender.equalsIgnoreCase("F"))
{
ActivityFactor = 1.9;
}
else if(inActivity.equalsIgnoreCase("F")&& inGender.equalsIgnoreCase("F"))
{
ActivityFactor = 2.2;
}
else
{
System.out.println("Please enter a valid choice!");
}
//CalculationMale
if(inActivity.equalsIgnoreCase("A")&& inGender.equalsIgnoreCase("M"))
{
ActivityFactor = 1.0;
}
else if(inActivity.equalsIgnoreCase("B")&& inGender.equalsIgnoreCase("M"))
{
ActivityFactor = 1.3;
}
else if(inActivity.equalsIgnoreCase("C")&& inGender.equalsIgnoreCase("M"))
{
ActivityFactor = 1.6;
}
else if(inActivity.equalsIgnoreCase("D")&& inGender.equalsIgnoreCase("M"))
{
ActivityFactor = 1.7;
}
else if(inActivity.equalsIgnoreCase("E")&& inGender.equalsIgnoreCase("M"))
{
ActivityFactor = 2.1;
}
else if(inActivity.equalsIgnoreCase("F")&& inGender.equalsIgnoreCase("M"))
{
ActivityFactor = 2.4;
}
else
{
System.out.println("Please enter a valid choice!");
}
//TDEE
double TD(ActivityFactor * BMR);
**Thanks you for all the answer. I do realize that if all the if/if else conditions do not go through, the " else" won't have a value for ActivityFactor. Thanks to all the reply, I now realize my way of pursuing this won't work. Could someone give me an outline of how I can code such a program that ask for the user name/gender/bmr then ask to select a activity level and assign an activity factor depending on whether the user is a male/female and their selection of activity level ?Thanks