More Methods Assignment

See this link for Assignment Policies, Submission Instructions, and Grading Guidelines.

Instructions

1.      IMPORTANT NOTE: Create 3 classes (class definitions) in the same file as your LastNameFirstNameX class (client) with 1 data field & 1 method for each class. Note that these are non-static variables & methods. The 3 classes should NOT have the keyword “public” in front of it.

2.      The 2nd, 3rd and 4th classes model a Sphere, a Regular Tetrahedron, and a Cube respectively. 

3.      The class definition for a Sphere should contain the following data field (attribute): diameter (radius = diameter / 2).

4.      The class definition for a Regular Tetrahedron should contain the following data field (attribute): side.

5.      The class definition for a Cube should contain the following data field (attribute): side.

6.      The class definitions of a Sphere, a Regular Tetrahedron, and a Cube should each contain the following 2 methods (behaviors): constructor & calculateVolume().

7.      The constructor should initialize the data field.

8.      The calculateVolume () method should return the volume of each shape.

9.      The 1st class is the client. It has the same name as LastNameFirstNameX. It has the main() method.

10.  In the main() method, ask the user to enter a number. Use either the Scanner or the JOptionPane class to ask for and get user input.

11.  In the main() method, instantiate (create)  a Sphere, a Regular Tetrahedron, and a Cube object. Use the constructor for each class to do this. So your program will have 3 variables – one variable for each shape. Each variable stores the address of an object. Each object is a Sphere, a Regular Tetrahedron, or a Cube.

12.  In the main() method, call the calculateVolume () method to calculate the volume of each shape. Each Sphere, Regular Tetrahedron, or Cube variable will have its own calculateVolume() method. Even though the 3 classes have the same name for the calculateVolume() method, the code for each method will do a different calculation.

13.  In the main() method, display the volume (NOT the area) of the 3 shapes. Use either System.out.println() or JOptionPane.showMessageDialog().

14.   Formulas: Volume of a cube = s3; Volume of a regular tetrahedron = 1/12 s3 √2; Volume of a sphere = 4/3 π r3 (radius = diameter / 2).

15.  Example I/O: If the number is 10, then the results should be cube = 1000, regular tetrahedron = 117.85113019775792073347406035081, sphere = 523.59877559829887307710723054658

16.  Don’t forget to use try-catch blocks, so that your program cannot crash.

17.  Make sure that your program follows the ICS 111 Java Coding Standard. The comments above each method should be written in the appropriate format.

 

 

© 2007 William Albritton