Q1. Create a class named Cuboid to represent cuboid objects and contains: • Three double attributes ①, W, and ʼn specifying the length, width and height of the cuboid. • A String attribute colour that specifies the colour of the cuboid. • A constructor (with 4 arguments) that creates a cuboid with specified values. • A constructor (with no arguments) that sets 1, w, and h to 1 and color to "white". This constructor should invoke the 4-argument constructor using the this keyword. • Your program must have these methods: 。 Getter methods for all fields (e.g. getColour () which returns the colour) о о getVolume: returns the cuboid volume which is 1*w*h getSurfaceArea(): returns the surface area of the cuboid: (2*(1*w + 1*h + w*h) displayInfo(): displays on the screen the colour, dimensions, surface area, and volume of this cuboid. Write a test program that creates two objects of the Cuboid class ⚫ the first object will have default values ⚫ the second object must be green of length = 8, width = 3.5, and height = 5.9. Print the dimensions, colour, surface area, and volume of each object as shown in the sample run below. Sample run: Cuboid 1 Color: White Dimensions: 1.00 X 1.00 X 1.00 Sruface Area: 6.00 Volume: 1.00 Cuboid 2 Color: Green Dimensions: 8.00 X 3.50 X 5.90 Sruface Area: 191.70 Volume: 165.20

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter11: Advanced Inheritance Concepts
Section: Chapter Questions
Problem 5PE
icon
Related questions
Question

dont use chatgbt to solve this question please and thank you. 

 

Q1. Create a class named Cuboid to represent cuboid objects and contains:
• Three double attributes ①, W, and ʼn specifying the length, width and height of the cuboid.
• A String attribute colour that specifies the colour of the cuboid.
• A constructor (with 4 arguments) that creates a cuboid with specified values.
• A constructor (with no arguments) that sets 1, w, and h to 1 and color to "white". This constructor
should invoke the 4-argument constructor using the this keyword.
• Your program must have these methods:
。 Getter methods for all fields (e.g. getColour () which returns the colour)
о
о
getVolume: returns the cuboid volume which is 1*w*h
getSurfaceArea(): returns the surface area of the cuboid: (2*(1*w + 1*h + w*h)
displayInfo(): displays on the screen the colour, dimensions, surface area, and volume of this cuboid.
Write a test program that creates two objects of the Cuboid class
⚫ the first object will have default values
⚫ the second object must be green of length = 8, width = 3.5, and height = 5.9.
Print the dimensions, colour, surface area, and volume of each object as shown in the sample run below.
Sample run:
Cuboid 1
Color: White
Dimensions: 1.00 X 1.00 X 1.00
Sruface Area: 6.00
Volume: 1.00
Cuboid 2
Color: Green
Dimensions: 8.00 X 3.50 X 5.90
Sruface Area: 191.70
Volume: 165.20
Transcribed Image Text:Q1. Create a class named Cuboid to represent cuboid objects and contains: • Three double attributes ①, W, and ʼn specifying the length, width and height of the cuboid. • A String attribute colour that specifies the colour of the cuboid. • A constructor (with 4 arguments) that creates a cuboid with specified values. • A constructor (with no arguments) that sets 1, w, and h to 1 and color to "white". This constructor should invoke the 4-argument constructor using the this keyword. • Your program must have these methods: 。 Getter methods for all fields (e.g. getColour () which returns the colour) о о getVolume: returns the cuboid volume which is 1*w*h getSurfaceArea(): returns the surface area of the cuboid: (2*(1*w + 1*h + w*h) displayInfo(): displays on the screen the colour, dimensions, surface area, and volume of this cuboid. Write a test program that creates two objects of the Cuboid class ⚫ the first object will have default values ⚫ the second object must be green of length = 8, width = 3.5, and height = 5.9. Print the dimensions, colour, surface area, and volume of each object as shown in the sample run below. Sample run: Cuboid 1 Color: White Dimensions: 1.00 X 1.00 X 1.00 Sruface Area: 6.00 Volume: 1.00 Cuboid 2 Color: Green Dimensions: 8.00 X 3.50 X 5.90 Sruface Area: 191.70 Volume: 165.20
Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning