Question: Create a project called genericshapes that will implement and use a generic class. The generic Class represents a Cuboid with length, breadth and height. The
- Create a project called genericshapes that will implement and use a generic class. The generic Class represents a Cuboid with length, breadth and height. The generic type will be used to accept the dimensions values either as integers or as decimal numbers.
- Create a generic class called Cuboid that will store the three dimensions of a cuboid length, breadth and height. Add the getters and setters for the dimensions.
- Override the toString() method so that it returns all of the dimensions as a string.
- The type of the dimensions will be decided at construction of the cuboid instance. Example: Cuboid
c1 = new Cuboid (); - The Class Cuboid must only accept values of the type Number (predefined in Java), or a subtype of Number, as a generic type for the dimensions.
- Add a method to the class that returns the volume of a Cuboid as a Double (l*b*h).
- Use the Cuboid class: create an instance doubleCuboid of the Cuboid class with the Double type and set the dimensions to custom decimal values.
- create an instance integerCuboid of the Cuboid class with the Integer type and set the dimensions to custom integer values.
- In the client class display the result of calling the getVolume() method on both the doubleCuboid and integerCuboid instances.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
