Question

In: Computer Science

I need to make this into a Java Code: Write a program that prompts the user...

I need to make this into a Java Code:

Write a program that prompts the user for a double value representing a radius. You will use the radius to calculate:

  • circleCircumference = 2πr
  • circleArea = πr2
  • sphereArea = 4πr2
  • sphereVolume = 43πr3

You must use π as defined in the java.lang.Math class.

Your prompt to the user to enter the number of days must be:

Enter radius:

Your output must be of the format:

Circle Circumference = circleCircumference
Circle Area = circleArea
Sphere Area = sphereArea
Sphere Volume = sphereVolume

Please make sure to end each line of output with a newline.

Please note that your class should be named CircleSphere.

Solutions

Expert Solution

import java.util.Scanner;

public class CircleSphere {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter radius: ");
        double radius = in.nextDouble();
        double circleCircumference = 2 * Math.PI * radius;
        double circleArea = Math.PI * radius * radius;
        double sphereArea = 4 * Math.PI * radius * radius;
        double sphereVolume = (4.0 / 3) * Math.PI * radius * radius * radius;
        System.out.println("Circle Circumference = " + circleCircumference);
        System.out.println("Circle Area = " + circleArea);
        System.out.println("Sphere Area = " + sphereArea);
        System.out.println("Sphere Volume = " + sphereVolume);
    }
}


Related Solutions

I need a java code Write a simple program to prompt the user for a number...
I need a java code Write a simple program to prompt the user for a number between 1 and 12 (inclusive) and print out the corresponding month. For example:   The 12th month is December. Use a java "switch" statement to convert from the number (1-12) to the month. Also use a "do while" loop and conditional checking to validate that the number entered is between 1 and 12 inclusive and if not, prompt the user again until getting the correct...
I need know how to Write a java program called character length that prompts the user...
I need know how to Write a java program called character length that prompts the user to enter a string and displays: The length of the string is: xxxxx The strings first character is: x    (where xxxxx is the length of the string and x is the first character.)
JAVA Program Write a program that prompts the user for data until the user wishes to...
JAVA Program Write a program that prompts the user for data until the user wishes to stop (you must have a while loop) (You must read in at least 8 to 10 sets of voter data using dialog boxes) The data to read in is: The registration of the voter (Democrat, Republican or other) The gender of the voter The Presidential candidate the voter is choosing (Trump or Biden) Which candidate has done better to manage the economy? (Trump or...
Write a program in JAVA that prompts the user for a lower bound and an upper...
Write a program in JAVA that prompts the user for a lower bound and an upper bound. Use a loop to output all of the even integers within the range inputted by the user on a single line.
JAVA: Write a program that prompts the user to input a type of medication and the...
JAVA: Write a program that prompts the user to input a type of medication and the output will be a list of side effects that can occur from that medication.
Write a java program that prompts the user to see if they wish to encode or...
Write a java program that prompts the user to see if they wish to encode or decode a message. (a) If they choose to encode a message: i. Ask them to enter the message and store it in a String variable. ii. Once the message is entered, ask them for a “shift” integer, similar to Lab 6. iii. Using that shift, move all alphabetic characters in the message (i.e. excluding spaces and punctuation) using char and int arithmetic. Be sure...
Write program#1 upload .java file. #1 Write a java program that prompts the user for input...
Write program#1 upload .java file. #1 Write a java program that prompts the user for input using the Scanner class. First to enter their first name. Then prompts the user to enter their last name. Then prompts the user to enter their city. Then prompts the user to enter their state. Then prompts the user to enter their zip code. Concatenate first name and last name into full_name. Using String Class is optional. Use the String Class to replace zip...
Write program#1 upload .java file. #1 Write a java program that prompts the user for input...
Write program#1 upload .java file. #1 Write a java program that prompts the user for input using the Scanner class. First to enter their first name. Then prompts the user to enter their last name. Then prompts the user to enter their city. Then prompts the user to enter their state. Then prompts the user to enter their zip code.   Concatenate first name and last name into full_name. Using String Class is optional. Use the String Class to replace zip...
This needs to be a python3 code Write a program that prompts the user like this:...
This needs to be a python3 code Write a program that prompts the user like this: “Currency to convert to U.S. dollars: e = Euros, c= Chinese Yuan, r = Indian Rupees, b = Bitcoin: ”. Then depending on which letter the user enters, the program displays “Amount of Euros/Yuan/Rupees/Bitcoin to convert: ”. (Note: the second prompt should only name the one currency the user asked to convert, not all four currencies.) After the user enters the amount, the program...
Write a Java program that prompts the user to input a word (String). The program must...
Write a Java program that prompts the user to input a word (String). The program must print the reversed word with all consecutive duplicate characters removed. The program must contain the following classes: - The StackX class (you can use the Java Stack class). - The Reverse class which must contain a private data field called “word” of type string, a constructor, and a void method called revNoDup(). The revNoDup() method must reverse the word and remove the consecutive duplicate...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT