165k views
12 votes
Write a java program named BMI.java(i)print out your name and your pantherID(ii) Ask user to type in his/her weight and height; if an illegal input (such as a letter) is typed by the user, give the user one more chance to input correctly.(iii)Create a method to compute the body mass index (BMI) accordingly. BMI

1 Answer

10 votes

Answer:

Answered below

Step-by-step explanation:

//Print name and ID

Scanner x = new Scanner(System.in);

System.out.print("Enter name");

String name = x.nextline();

Scanner y = new Scanner(System.in);

System.out.print("Enter ID");

int id = y.nextline();

System.out.println(name, id);

Scanner w = new Scanner(System.in);

System.out.print("enter weight");

double weight = w.nextline();

Scanner h = new Scanner(System.in);

System.out.print("enter height: ");

double height = h.nextline();

int i = 0;

while( I < 2){

if ( !isDigit(weight) && !isDigit(height){

Scanner w = new Scanner(System.in);

System.out.print("enter weight:);

weight = w.nextline();

Scanner h = new Scanner(System.in);

System.out.print("enter height");

height = h.nextline();

}else{

break;

double BMI = weight / ( height **2)

System.out.print(BMI)}

I++

}

User Wang Liang
by
5.5k points