Question

Question 1 Write a program that reads from the user the height and radius of a...

Question 1
Write a program that reads from the user the height and radius of a cylinder, and then outputs the area of this cylinder. The area of the cylinder is calculated using the formula:
A=2*π*r*h+2*π*r2, where π = 3.14.
Sample run:
Enter the radius of the cylinder: 8.2
Enter the height of the cylinder: 9
The area of the cylinder is 885.75

Question 2
Write a program that reads the name, weight and height of a patient. Then the program outputs if the patient is under weight, average or over weight based on the following formula:
BMI = weight/height2
BMI < 20: Underweight
BMI between 20 and 25: Average
BMI > 25: Over weight

Sample run 1:
Enter your name: Samar
Enter your weight in kg: 70
Enter your height by meters: 1.67
Samar is overweight

Sample run 2:
Enter your name: Rola
Enter your weight in kg: 48
Enter your height by meters: 1.5
Rola is average

Sample run 3:
Enter your name: Rami
Enter your weight in kg: 85
Enter your height by meters: 1.88
Rami is underweight

Java language

Homework Answers

Answer #1

Question 1:

  1. create Scanner object
  2. declare radius
  3. declare height
  4. declare and initialize pi
  5. print message and read radius
  6. print message and  read height
  7. calculate area
  8. print area

Program: Cylinder.java


import java.util.Scanner;
public class Cylinder{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);                                            /* create Scanner object */
                double radius;                                                                                          /* declare radius */
                double height;                                                                                          /* declare height */
                double pi = 3.14;                                                                                       /* declare and initialize pi */
                System.out.print("Enter the radius of the cylinder: ");         /* print message */
                radius = sc.nextDouble();                                                                       /* read radius */
                System.out.print("Enter the height of the cylinder: ");         /* print message */
                height = sc.nextDouble();                                                                       /* read height */
                double area = 2*pi*radius*height + 2*pi*radius*radius;          /* calculate area */
                System.out.println("The area of the cylinder is " + area);      /* print area */
        }
}
                

Screenshot:

Output:

Question 2:

  1. create Scanner object
  2. declare weight and height
  3. initialize BMI
  4. print message and read name
  5. print message and read weight
  6. print message and  read height
  7. calculate BMI
  8. if BMI<20, print underweight
  9. if BMI>25,  print overweight
  10. otherwise, print average

Program: BMI.java


import java.util.Scanner;
public class BMI{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);                                            /* create Scanner object */
                double weight;                                                                                          /* declare weight */
                double height;                                                                                          /* declare height */
                double BMI;                                                                                             /* initialize BMI */
                String name;
                System.out.print("Enter your name: ");                                          /* print message */
                name = sc.nextLine();                                                                           /* read name */
                System.out.print("Enter your weight in kg: ");                          /* print message */
                weight = sc.nextDouble();                                                                       /* read weight */
                System.out.print("Enter your height in meters: ");                      /* print message */
                height = sc.nextDouble();                                                                       /* read height */
                BMI = weight/(height*height);                                                           /* calculate BMI */
                if(BMI<20){
                        System.out.println(name + " is underweight");                   /* print underweight */
                }
                else if(BMI>25){
                        System.out.println(name +" is overweight");                     /* print overweight */
                }
                else{
                        System.out.println(name + " is average");                               /* print average */
                }
        }
}
                

Screenshot:

Output:

Please don't forget to give a Thumbs Up.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
The Body Mass Index (BMI) is a calculation used to categorize whether a person’s weight is...
The Body Mass Index (BMI) is a calculation used to categorize whether a person’s weight is at a healthy weight for a given height. The formula is as follows:                 bmi = kilograms / (meters2)                 where kilograms = person’s weight in kilograms, meters = person’s height in meters BMI is then categorized as follows: Classification BMI Range Underweight Less than 18.5 Normal 18.5 or more, but less than 25.0 Overweight 25.0 or more, but less than 30.0 Obese 30.0...
Write a Python program named lastNameVolumes that finds the volumes of different 3 D objects such...
Write a Python program named lastNameVolumes that finds the volumes of different 3 D objects such as a cube, sphere, cylinder and cone. In this file there should be four methods defined. Write a method named cubeVolFirstName, which accepts the side of a cube in inches as an argument into the function. The method should calculate the volume of a cube in cubic inches and return the volume. The formula for calculating the volume of a cube is given below....
Use C++ Write a program that first reads in how many whole numbers the user wants...
Use C++ Write a program that first reads in how many whole numbers the user wants to sum, then reads in that many whole numbers, and finally outputs the sum of all the numbers greater than zero, the sum of all the numbers less than zero (which will be a negative number or zero), and the sum of all the numbers, whether positive, negative, or zero. The user enters the numbers just once each and the user can enter them...
(Write in C++) Write a program that reads in two numbers and, if the input is...
(Write in C++) Write a program that reads in two numbers and, if the input is valid, outputs 2 times the product of the integers that lie between the two values (including the values themselves). If either number is not an integer, or if the first number is not less than the second number, just output an error message. The sample runs below should give the idea. User inputs are in bold. Important Notes: Your program should use a loop...
In C programming, Thank you Write a program to compute the area of a circle. You...
In C programming, Thank you Write a program to compute the area of a circle. You have to write a complete “C” program that compiles and runs in Codeblocks. Program requirements: 1. Declare the variables needed: radius (r) and area (yourLastName). 2. Calculate and print the area of each circle. 3. The program MUST prompt the user for a new radius (r) over and over until the user types -1. 5. Use the type double for all decimal numbers. 6....
JAVA (Don't make it too complicated) Write a program that prompts the user for the name...
JAVA (Don't make it too complicated) Write a program that prompts the user for the name of a text file. The file should consist of a sequence of integers, one integer per line. The program will read in each line (using nextLine()), parse it as an int (using Integer.parseInt()), and report the number of values and their average. The average should be computed as a double. Your program should do some basic exception handling: (1) If the file cannot be...
Write a program that does the following in order: 1. Ask user to enter a name...
Write a program that does the following in order: 1. Ask user to enter a name 2. Ask the user to enter five numbers “amount1”, “amount2”, “amount3”, “amount4”, “amount5” 3. Calculate the sum of the numbers “amount1”, “amount2”, “amount3”, “amount4”, “amount5” 4. If the sum is greater than 0, print out the sum 5. If the sum is equal to zero, print out “Your account balance is zero” 6. If the sum is less than 0, print out “Your account...
Java: Distance calc. This question is fairly straightforward. Design implement (source code) a program to compute...
Java: Distance calc. This question is fairly straightforward. Design implement (source code) a program to compute the distance between 2 points. The program prompts the user to enter 2 points (X1, Y1) and (X2, Y2). The distance between 2 points formula is: Square_Root [(X2 – X1)^2 + (Y2 – Y1)^2] Document your code, properly label the input prompts, and organize the outputs as shown in the following sample runs. Note: for C++, #include and then call sqrt(). For Java, you’ll...
Write a program that reads a binary string (string of 0’s and 1’s) converting the binary...
Write a program that reads a binary string (string of 0’s and 1’s) converting the binary value into decimal. Allow the user to type in as many numbers as they want (one at a time) and end the program when they type in “0”. Use Horner’s method (given in step 3, below) to convert from binary to decimal. Sample Run Binary to Decimal Conversion Enter a binary string: 1101 1101 = 13 decimal Enter a binary string: 10011001 10011001 =...
#include<iostream> #include<iomanip> using namespace std; int main() { //variables int choice; float radius,base,height,area; const double PI=3.14159;...
#include<iostream> #include<iomanip> using namespace std; int main() { //variables int choice; float radius,base,height,area; const double PI=3.14159; //repeat until user wants to quits while(true) { //menu cout<<endl<<endl<<"Geometry Calculator"<<endl<<endl; cout<<"1. Calculate the area of a circle"<<endl; cout<<"2. Calculate the area of a triangle"<<endl; cout<<"3. Quit"<<endl<<endl; //prompt for choice cout<<"Enter your choice(1-3): "; cin>>choice; cout<<endl; //if choice is circle if(choice==1) { cout<<"What is the radius of the circle? "; cin>>radius; //calculating area area=PI*radius*radius; cout<<endl<<"The area of the circle is "<<fixed<<setprecision(3)<<area<<endl; } //if choice...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT