Advertisement
Dakpluto

PartB.java

Oct 28th, 2014
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.30 KB | None | 0 0
  1. import java.text.DecimalFormat;
  2. import java.util.Scanner;
  3.  
  4. public class PartB {
  5.  
  6.     public static void main(String[] args) {
  7.         double radius;
  8.         Scanner userInput = new Scanner(System.in);
  9.  
  10.         DecimalFormat df = new DecimalFormat("#.000");
  11.  
  12.         System.out.println("Input the radius: ");
  13.         radius = userInput.nextDouble();
  14.  
  15.         System.out.println("The Circumference of the Circle is: "
  16.                 + df.format(calculateCircumference(radius)));
  17.         System.out.println("The Diameter of the Circle is: "
  18.                 + df.format(calculateDiameter(radius)));
  19.         System.out.println("The Area of the Circle is: "
  20.                 + df.format(calculateCircleArea(radius)));
  21.         System.out.println("The Volume of the Sphere is: "
  22.                 + df.format(calculateVolumeSphere(radius)));
  23.     }
  24.  
  25.     public static double calculateCircumference(double radius) {
  26.         double result;
  27.  
  28.         result = 2 * Math.PI * radius;
  29.         return result;
  30.     }
  31.  
  32.     public static double calculateDiameter(double radius) {
  33.         double result;
  34.  
  35.         result = radius * 2;
  36.         return result;
  37.     }
  38.  
  39.     public static double calculateCircleArea(double radius) {
  40.         double result;
  41.  
  42.         result = Math.PI * Math.pow(radius, 2);
  43.         return result;
  44.     }
  45.  
  46.     public static double calculateVolumeSphere(double radius) {
  47.         double result;
  48.  
  49.         result = (4.0 / 3.0) * Math.PI * Math.pow(radius, 3);
  50.         return result;
  51.     }
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement