Question 1 question1java 20 marks Write a single class that

Question 1. (question1.java) (20 marks) Write a single class that has the methods:
public static double sphereVolume(double r)
public static double sphereSurface(double r)
public static double coneVolume(double r, double h)
public static double coneSurface(double r, double h)

Then write a main() method that prompts the user for values for r (radius) and h (height) and calls all of the
other methods to displays the results. Your main() method takes care of all input collection and printing of the
results – make use of the method arguments and return values. You do not need to do any error checking on the
input values.

C:\\Users\\aaron\\Desktop\\java SphereAndCone
Enter a value for radius:1
Enter a value for height:1
Sphere Volume: 4.1887902047863905
Sphere Surface Area: 12.566370614359172
Cone Volume: 1.0471975511965976
Cone Surface Area: 7.584475591748159

C:\\Users\\aaron\\Desktop\\java SphereAndCone
Enter a value for radius:5.5
Enter a value for height:12.2
Sphere Volume: 696.9099703213358
Sphere Surface Area: 380.132711084365
Cone Volume: 386.46825626910436
Cone Surface Area: 326.26533476656743

Solution

SphereAndCone.java

import java.util.Scanner;


public class SphereAndCone {


   public static void main(String[] args) {
       Scanner scan = new Scanner(System.in);
   System.out.print(\"Enter a value for radius: \");
   double radius = scan.nextDouble();
   System.out.print(\"Enter a value for height: \");
   double height = scan.nextDouble();
   System.out.println(\"Sphere Volume is \"+sphereVolume(radius));
   System.out.println(\"Sphere Surface Volume is \"+sphereSurface(radius));
   System.out.println(\"Cone Volume is \"+coneVolume(radius,height));
   System.out.println(\"Cone Surface Volume is \"+coneSurface(radius, height));    
   }
   public static double sphereVolume(double r){
       double volumn = (4 * Math.PI * r *r * r )/3;
       return volumn;
   }
   public static double sphereSurface(double r){
       return (4 * Math.PI * r * r );
   }
   public static double coneVolume(double r, double h){
       return (Math.PI * r * r * h )/3;
   }
   public static double coneSurface(double r, double h){
       return Math.PI * r * (r + Math.sqrt(h * h + r * r));
   }

}

Output:

Enter a value for radius: 1
Enter a value for height: 1
Sphere Volume is 4.1887902047863905
Sphere Surface Volume is 12.566370614359172
Cone Volume is 1.0471975511965976
Cone Surface Volume is 7.584475591748159

Enter a value for radius: 5.5
Enter a value for height: 12.2
Sphere Volume is 696.9099703213357
Sphere Surface Volume is 380.1327110843649
Cone Volume is 386.46825626910436
Cone Surface Volume is 326.2653347665674

Question 1. (question1.java) (20 marks) Write a single class that has the methods: public static double sphereVolume(double r) public static double sphereSurfac
Question 1. (question1.java) (20 marks) Write a single class that has the methods: public static double sphereVolume(double r) public static double sphereSurfac

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site