Question
1. Create a class named Room that has two fields: length of the room and width of the room. The Room class should have a
1. Create a class named Room that has two fields: length of the room and width of the room. The Room class should have a constructor that sets the length and width. It also should have get methods for Length and Width. Finally, it should have a method that returns the area of the room where the area of the room is the rooms length multiplied by the rooms width.
2. Next, create a RoomCarpet that has a Room object as a field. It also has a field for the cost of the carpet per square foot of carpet. - The RoomCarpet class has a constructor that takes Room object and cost as an argument and creates a Room object and set the cost field. - It should also have a method that returns the total cost of the carpet i.e., room area times cost per square foot.
3. Write a Demo class that uses both of these classes and get input from the user for length, width, and cost per square foot and prints the area of the room and the cost of carpeting the room
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