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
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...
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....
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...
x86 irvine library assembly code Write a complete program that: 1. Prompt the user to enter...
x86 irvine library assembly code Write a complete program that: 1. Prompt the user to enter 10 numbers. 2. save those numbers in a 32-bit integer array. 3. Print the array with the same order it was entered. 3. Calculate the sum of the numbers and display it. 4. Calculate the mean of the array and display it. 5. Rotate the members in the array forward one position for 9 times. so the last rotation will display the array in...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in Lab 2 to obtain a diameter value from the user and compute the volume of a sphere (we assumed that to be the shape of a balloon) in a new program, and implement the following restriction on the user’s input: the user should enter a value for the diameter which is at least 8 inches but not larger than 60 inches. Using an if-else...
QUESTION 1 Physical examination technique is which the nurse uses striking of a part of the...
QUESTION 1 Physical examination technique is which the nurse uses striking of a part of the body with short, sharp taps of the fingers ___________ A) Percussion. B) Palpation. C) Auscultation. D) Inspection. 0.5 points    QUESTION 2 All these equipment should be used in eye assessment except____________ A) Snellen eye chart B) Otoscope C) Penlight D) Opaque card or occluder 0.5 points    QUESTION 3 Common clinical features or Associated Factors with pain include all except__________ A) Skin rash,...
Question 1. (4 marks) Recall your consultancy work for Drovandi Marketing and Networks (DMN) from your...
Question 1. Recall your consultancy work for Drovandi Marketing and Networks (DMN) from your last PST. In the final phase of your current project, MXB101, you are required to delve into the minds of customers. DMN has taken a large survey of customers buying a particular product. From this survey, they know that: 25% of customers are under 25. 60% of customers are between 25 and 50. 15% of customers are over 50. DMN estimates that 20% of the population...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT