Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Project 2 Write an interactive Java program. The program should prompt the user

ID: 3671684 • Letter: P

Question

Project 2 Write an interactive Java program. The program should prompt the user to enter their first, and last name separately. Then prompt the user for a radius and height. Finally, prompt the user to enter a binary number. Generate two random numbers, a whole number between 1 and the binary number entered, and a decimal number between 1.0-10.0. Output the paragraph below using the information you collected and generated. Be sure the cylinder volume numbers have exactly 4 decimal places. Notes: Volume = PI * radius^2 * height You will need to use the following classes: Scanner, Math, DecimalFormat, Random, Integer. Program Example Enter your first name: Justin Enter your last name: Turner Enter a radius: 5 Enter a height: 10 Enter a binary number: 101010 Hello Justin Turner, The cylinder with a radius of 5 and a height of 10 has a volume of 785.3982. A random cylinder with a radius of 3 and a height of 5.6780 has a volume of 160.5417. The binary value of 101010 is equal to 42. Requirements for all projects: • Use appropriate code design and code documentation • Correct compilation, correct execution, and correct results and output without any errors. • Contain the following documentation as a header for the program, use any format: o Your name o Class name o Project number o Project due date o Program title o Program description • Submit the project using the D2L drop box

Explanation / Answer


import java.util.Scanner;


public class Prompt {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter first name");
//entering the first name
String first=sc.next();
//entering the last name
System.out.println("Enter Last name");
String last=sc.next();
//entering the radius
System.out.println("Enter Radius");
float rad=sc.nextFloat();
//Enter Height
System.out.println("Enter height");
float height=sc.nextFloat();
//entering binary number
System.out.println("Enter binary number");
String binaryString =sc.next();
//converting given binary to decimal
int bd=Integer.parseInt(binaryString,2);
// generating random radious between 1 and given binary num
double randrad=(Math.random())*bd;
//generating random height between 1 and 10
double randht=(Math.random())*10;
//Caluclating volume for both cylinders
double vol1=3.14*rad*rad*height;
double vol2=3.14*randrad*randrad*randht;
  
System.out.println("Hello "+first+" "+last);
System.out.println("volume of Cylinder with radious "+rad+" height "+height+"is"+vol1);
System.out.println("Random Cylinder volume with radious "+randrad+" height "+randht+"is"+vol2);
  
  
}
}