Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Hugh Gordon
- * Cube set & get Exercise
- * This class file demonstrates the Cube class' methods
- * It will instantiate a Cube object and print out the default qualities or the qualities you assign it
- */
- import java.io.*;
- import java.util.Scanner;
- public class cubeMain {
- public static void main(String[] args) throws IOException {
- Cube c = new Cube(); // Create a Cube object witht he default constructor
- Scanner sc = new Scanner(System.in);
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- 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
- switch (change) { // Make a decision based on their answer with switch-case
- case "yes": // If they say yes then prompt them for the various cube properties
- System.out.print("How many inches are one side?"); c.setSide(sc.nextDouble());
- System.out.print("What color is the cube?"); c.setColor(br.readLine());
- System.out.print("Is the cube hollow? (true|false)"); c.setFill(sc.nextBoolean());
- case "no": // Either way print out the properties of the cube
- default:
- System.out.printf("Length: %.2f%n", c.getSide()); // Format the length to 2 decimal places
- System.out.printf("Volume: %.2f%n", c.getVolume()); // Format the volume to 2 decimal places
- System.out.printf("Surface Area: %.2f%n", c.getSurfaceArea()); // Format the surface area to 2 decimal places
- System.out.println("Color: " + c.getColor());
- System.out.println("Filled: " + c.isFilled());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment