i have to make a body mass index calculator in java for an assignment, and if the user enters an alphabetic character when it asks for weight, i want the program to quit and display a message. i need help creating the if statement. here is what i have (which isn't working). i have tried various other inequality symbols with no success. i thought i may have to use a if (between command) but i did not discover a way to make that work with the weight variable.
The error i recieve is as follows Lab4.java:21: error cannot find symbol if (weight <= Z) ^
public class Lab4
{
public static void main (String[] args)
{
Scanner kb = new Scanner (System.in);
System.out.println("enter e for english or m for metric");
String choice;
choice = kb.nextLine();
char firstchar;
firstchar = choice.charAt(0);
boolean english;
english = firstchar == 'e';
if (english)
{
// prompt the user to input their weight in pounds
System.out.println("Enter your weight in pounds");
double weight = kb.nextDouble();
if (weight <= Z)
{
System.out.println("letters are not an acceptable weight");
System.exit(0);
}
// prompt the user to input their height in inches
System.out.println("Enter your height in inches");
double height = kb.nextDouble();
if (height == 0.0)
{
System.out.println("0 is not a valid height");
System.exit(0);
}
// make bmi to an integer and compute bmi by dividing weight by height^2 * 750
int bmi = (int)(weight/(height*height)*703);
// have the computer display height, wieght, and bmi
System.out.printf("your weight is %8.2f", weight);
System.out.println(" pounds");
System.out.printf("your height is %8.2f", height);
System.out.println(" inches");
System.out.println("your BMI is " + bmi);
if (bmi <= 24)
System.out.println("Normal Bodyweight");
else
{
if (bmi > 30)
System.out.println("Obese");
else
System.out.println("Overweight");