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

  1. 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.
    1. 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.
    2. Override the toString() method so that it returns all of the dimensions as a string.
    3. The type of the dimensions will be decided at construction of the cuboid instance. Example: Cuboid c1 = new Cuboid();
    4. 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.
    5. Add a method to the class that returns the volume of a Cuboid as a Double (l*b*h).
    6. Use the Cuboid class: create an instance doubleCuboid of the Cuboid class with the Double type and set the dimensions to custom decimal values.
    7. create an instance integerCuboid of the Cuboid class with the Integer type and set the dimensions to custom integer values.
    8. 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 blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!