Question

In: Computer Science

2.26 Homework 2-3 Write a program that prompts the user for a double value representing a...

2.26 Homework 2-3 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 = Unknown node type: sup πrUnknown node type: sup sphereArea = Unknown node type: sup 4πrUnknown node type: sup sphereVolume = Unknown node type: sup 43πrUnknown node type: sup 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 scanner = new Scanner(System.in);
        double r;
        System.out.print("Enter radius: ");
        r = scanner.nextDouble();

        double circleArea = Math.PI*Math.pow(r,2);
        double circleCircumference = 2*Math.PI*r;
        double sphereArea = 4*Math.PI*Math.pow(r,2);
        double sphereVolume = (4.0/3)*Math.PI*Math.pow(r,3);

        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

Write a program that prompts the user to enter a 3 x 3 matrix of double...
Write a program that prompts the user to enter a 3 x 3 matrix of double values and tests whether it is a positive Markov matrix. There will be two methods which will be called from the main method: public static double [] [] createArray() 1. Creates a 3 by 3 two dimensional array of doubles 2. Prompts the user for values as shown in the sample run 3. Stores the numbers in the array in the order entered 4....
Write a program that prompts the user to enter a 3 x 3 matrix of double...
Write a program that prompts the user to enter a 3 x 3 matrix of double values and tests whether it is a positive Markov matrix. There will be two methods which will be called from the main method: public static double [] [] createArray() 1. Creates a 3 by 3 two dimensional array of doubles 2. Prompts the user for values as shown in the sample run 3. Stores the numbers in the array in the order entered 4....
Write a program that prompts the user to enter a 3 x 3 matrix of double...
Write a program that prompts the user to enter a 3 x 3 matrix of double values and tests whether it is a positive Markov matrix. There will be two methods which will be called from the main method: public static double [] [] createArray() 1. Creates a 3 by 3 two dimensional array of doubles 2. Prompts the user for values as shown in the sample run 3. Stores the numbers in the array in the order entered 4....
Part 1 Write a program that prompts the user to enter three sets of five double...
Part 1 Write a program that prompts the user to enter three sets of five double numbers each. These numbers represent the five grades that each of three students has received. After prompting for the grades, the program: stores the data in a previously defined 3◊5 double array computes the average of each set of 5 grades after acquiring the grades for that one student determines the maximum and minimum values of each set of 5 grades acquiring the grades...
Write a C program that prompts the user to enter three sets of five double numbers...
Write a C program that prompts the user to enter three sets of five double numbers each. (You may assume the user responds correctly and doesn’t enter non-numeric data.) The program should accomplish all of the following: a. Store the information in a 3×5 array. b. Compute the average of each set of five values. c. Compute the average of all the values. d. Determine the largest value of the 15 values. e. Report the results. Each major task should...
Include<stdio.h> In C program Write a program that prompts the user to enter an integer value....
Include<stdio.h> In C program Write a program that prompts the user to enter an integer value. The program should then output a message saying whether the number is positive, negative, or zero.
For this portion of Lab #2, write a program that prompts the user to enter ten...
For this portion of Lab #2, write a program that prompts the user to enter ten integer values between 1 and 100, determines the smallest and largest values entered by the user as well as the average of all the numbers entered by the user (expressed as a floating-point number), and then prints the smallest number, the largest number, and the average. Print each of these values with descriptive labels. Your program output should resemble the following (the user's input...
Write a C++ program which prompts the user to enter an integer value, stores it into...
Write a C++ program which prompts the user to enter an integer value, stores it into a variable called ‘num’, evaluates the following expressions and displays results on screen. num+5, num-3, (num+3) – 2, ((num+5)*2 / (num+3)) For performing addition and subtraction, you are allowed to use ONLY the increment and decrement operators (both prefixing and postfixing are allowed). You must remember that using increment/decrement operators changes the original value of a number. Indent your code and include comments for...
Write a C++ program that prompts the user (or “Player 1”) to input an integer value...
Write a C++ program that prompts the user (or “Player 1”) to input an integer value between 1 and 3 (where 1=paper, 2=scissor, and 3=rock). This input should be passed into a string function called player_RPS(), and returns a string value indicating the selection of paper, scissors, or rock (as mentioned above). Next, the returned string value, along with a generated input from the computer, should be passed into a void function called RPS_comparison(), and determines whether the user’s input...
write this program in C++ Write a program that prompts a user for three characters. The...
write this program in C++ Write a program that prompts a user for three characters. The program must make sure that the input is a number 10 - 100 inclusive. The program must re prompt the user until a correct input is entered. Finally output the largest and the lowest value. Example 1: Input : 10 Input : 20 Input : 30 The largest is 30. The lowest is 10. Example 2: Input : 100 Input : 50 Input :...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT