Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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