KHD

Cube Main

KHD
Sep 23rd, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.66 KB | None | 0 0
  1. /* Hugh Gordon
  2.  * Cube set & get Exercise
  3.  * This class file demonstrates the Cube class' methods
  4.  * It will instantiate a Cube object and print out the default qualities or the qualities you assign it
  5.  */
  6.  
  7. import java.io.*;
  8. import java.util.Scanner;
  9.  
  10. public class cubeMain {
  11.   public static void main(String[] args) throws IOException {
  12.     Cube c = new Cube(); // Create a Cube object witht he default constructor
  13.     Scanner sc = new Scanner(System.in);
  14.     BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  15.     System.out.print("Would you like to change the properties of your cube?"); String change = br.readLine(); // Prompt the user if they want to change their cube and read the answer
  16.     switch (change) { // Make a decision based on their answer with switch-case
  17.       case "yes": // If they say yes then prompt them for the various cube properties
  18.         System.out.print("How many inches are one side?"); c.setSide(sc.nextDouble());
  19.         System.out.print("What color is the cube?"); c.setColor(br.readLine());
  20.         System.out.print("Is the cube hollow? (true|false)"); c.setFill(sc.nextBoolean());
  21.       case "no": // Either way print out the properties of the cube
  22.       default:
  23.         System.out.printf("Length: %.2f%n", c.getSide()); //  Format the length to 2 decimal places
  24.         System.out.printf("Volume: %.2f%n", c.getVolume()); //  Format the volume to 2 decimal places
  25.         System.out.printf("Surface Area: %.2f%n", c.getSurfaceArea()); //  Format the surface area to 2 decimal places
  26.         System.out.println("Color: " + c.getColor());
  27.         System.out.println("Filled: " + c.isFilled());
  28.     }
  29.   }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment