![]() |
Assignment 5TaskExplore static methods and simple loops. Steps
Write a short program named Step 1: Static MethodsWrite four static methods that calculate the following details of a sphere:
Each method should take a double parameter (the radius of the sphere) and return a double (the result of the calculation). Here is some code to get you started: public class Assignment5 { public static void main(String[] args) { double radius = 5; System.out.println("For a sphere with radius " + radius + ": "); System.out.println("Diameter = " + getDiameter(radius)); //... } public static double getDiameter(double radius) { return (radius * 2); } } Step 2: User Input
Now use a Step 3: Loop
Now add a loop that asks the user if they would like to enter another radius. (A Sample OutputHere is some sample output for the finished program: Enter the radius of a sphere: 5 For a sphere with radius 5.0: Diameter = 10.0 Circumference = 31.41592653589793 Surface area = 314.1592653589793 Volume = 523.5987755982989 Would you like to display the details of another sphere (yes/no)? yes Enter the radius of a sphere: 10 For a sphere with radius 10.0: Diameter = 20.0 Circumference = 62.83185307179586 Surface area = 1256.6370614359173 Volume = 4188.790204786391 Would you like to display the details of another sphere (yes/no)? no What to submit
Attach your GradingOut of 10 points:
|
~ztomasze Index :
TA Details: ICS111:
Assignment 5 http://www2.hawaii.edu/~ztomasze |
Last Edited: 22 May 2008 ©2008 by Z. Tomaszewski. |