Notes . In if-else statements, indent statements to be executed for if or else c
ID: 3602673 • Letter: N
Question
Notes . In if-else statements, indent statements to be executed for if or else conditions three to five spaces. Align else or else if with corresponding if. If functions are required, include a statement of purpose for each function. Prompt the user to enter the first letter of the color of a cylinder. Then use a switch statement, output the contents of the cylinder to the console screen, using this table 1. For a cylinder of this color Orange Brown Yellow Green User inputs It contains this B" or 'b Y' or Ammonia Carbon Monoxide Hydrogen 2. Write a program that calculates the user's body mass index(BMI) and categorizes it as underweight, normal, overweight or obese base on the table below: BMI Below 18.5 18.5-24.9 25.0-29.9 30.0 and above Weight Status Underweight Normal Overweight Obese Prompt the user to enter the person's weight in pounds and the person's height in inches. Use the following formula to calculate the BMI 703 * weight height2 BMI = Output the calculated BMI to the console window and the determined "weight status" based on that number. Test with 200 pounds and 72 inches You must use a ifelse ifelse structure for this problem.Explanation / Answer
BMITest.java
import java.util.Scanner;
public class BMITest {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter the weight: ");
double weight = scan.nextDouble();
System.out.println("Enter the height: ");
double height = scan.nextDouble();
double BMI = (weight * 703)/(height * height);
if(BMI >= 30) {
System.out.println("Obese");
} else if(BMI >=25 && BMI <30) {
System.out.println("Overweight");
} else if(BMI >=18.5 && BMI <25) {
System.out.println("Normal");
} else {
System.out.println("Underweight");
}
}
}
Output:
Enter the weight:
45
Enter the height:
5
Obese
ColorsTest.java
import java.util.Scanner;
public class ColorsTest {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter the letter of color: ");
char c = scan.next().charAt(0);
switch(c) {
case 'O':
case 'o':System.out.println("Orange. It contains Ammonia"); break;
case 'B':
case 'b':System.out.println("Brown. It contains Corbon Monoxide"); break;
case 'Y':
case 'y':System.out.println("Yellow. It contains Hydrogen"); break;
case 'G':
case 'g':System.out.println("Green. It contains Oxygen"); break;
default:System.out.println("Invalid Input");
}
}
}
Output:
Enter the letter of color:
y
Yellow. It contains Hydrogen
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.