Answered step by step
Verified Expert Solution
Question
1 Approved Answer
JAVA CODE REQUIRED implementation for class Cube that has a private instance variable side of type int. Provide a default constructor that initializes the side
JAVA CODE REQUIRED
implementation for class Cube that has a private instance variable side of type int.
- Provide a default constructor that initializes the side of the Cube to one
- Provide a constructor that initializes the side of the Cube using a parameter.
- Provide an accessor method and mutator method. In the mutator method ensure that the side is greater than or equal to 1 using a conditional statement.
- Provide a method that computes the surface area of a Cube.
- Provide a method that computes the volume of a Cube.
- Provide a toString method that will return a String containing the value of side of the cube in the format 0.0.
Implement an application class CubeTest to test the Cube class you defined above. Ensure that all your methods and constructors work properly.
- Create a scanner object.
- Create a Cube using the default constructor
- Prompt user to enter a value for the side of the default Cube and read the side value.
- Use the mutator method to change the side of the default Cube.
- Create an additional cube object using the parameter constructor.
- Create one more cube object using the parameter constructor
- get the value of the default Cube side using the accessor method and store in an integer variable.
- Print the surface area of one of your Cube Objects (not the default) using the appropriate method.
- Print the volume of one of your Cube Object (not the default or the one in used in #7) using the appropriate method.
- Print all three Cube Objects using an implicit call to toString.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started