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
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....
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...
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...
Problem 1 (Defining products and Creating a Menu) Write a program called a2_p1.py that asks a...
Problem 1 (Defining products and Creating a Menu) Write a program called a2_p1.py that asks a shop owner for product information and creates a menu system that allows customers to purchase multiple products of varying quantities. The program should start by asking the shop owner’s name (string) and company name (string). Next it should ask for three (3) products (strings), their prices (int – not ideal, but for now we will keep it this way), and the number of products...
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...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT