Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Westfield Carpet Company has asked you to write an application that calculates the price of carpeting for rectangular rooms. To calculate the price, you

The Westfield Carpet Company has asked you to write an application that calculates the price of carpeting for rectangular rooms. To calculate the price, you multiply the area of the floor (width times length) by the price per square foot of carpet. For example, the area of the floor that is 12 feet long and 10 feet wide is 120 square feet. To cover that floor with carpet that costs $8 per square foot would cost $960.

First, you should create a class named RoomDimension that has two fields: one for the length of the room and one for the width of the room. The RoomDimension class should have a method that returns the area of the room.

Next, you should create a RoomCarpet class that has a RoomDimension object as a field. It should also have a field for the cost of the carpet per square foot. The RoomCarpet class should have a method that calculates and returns the cost of the carpet.

Once you have the two classes, write a test program to ask the user to enter the dimensions of a room and the price per square foot of the desired carpeting. Then display the total cost of the carpet.

RoomCarpet -size: RoomDimension carpetCost: double +RoomCarpet dim: RoomDimension, cost: double): +RoomCarpetCrc: RoomCarpet to: double +getSize 0: RoomDimension tgetCarpetCost0: double +toString Strin RoomDimension -length: double -width: double +RoomDimension(den: double, wid: double) +RoomDimensi onard: Room Dimension +get Area0: double +toString Strin

You will write three java files:

1. RoomDimension.java: defines the RoomDimension class

2. RoomCarpet.java: defines the RoomCarpet class, which has a RoomDimension object as a data field

3. the test program

RoomCarpet -size: RoomDimension -carpetCost: double +RoomCarpet(dim: RoomDimension, cost: double): +RoomCarpet(rc: RoomCarpet) +getTotalCost(): double +getSize(): RoomDimension +getCarpetCost(): double +toString(): String | RoomDimension -length: double -width:double +RoomDimension(len: double, wid: double) +RoomDimension(rd: RoomDimension) +getArea(): double +toString(): String

Step by Step Solution

3.42 Rating (165 Votes )

There are 3 Steps involved in it

Step: 1

class RoomDimension Variables for length and width of Room int length int width Set Functions to set ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial Management for Public Health and Not for Profit Organizations

Authors: Steven A. Finkler, Thad Calabrese

4th edition

133060411, 132805669, 9780133060416, 978-0132805667

More Books

Students also viewed these Computer Engineering questions

Question

Why is globalization of industries a common factor today?

Answered: 1 week ago

Question

What background experience do you have?

Answered: 1 week ago

Question

Why would CPAs prefer to avoid estimates in financial reporting?

Answered: 1 week ago

Question

What is the role of the long-range plan?

Answered: 1 week ago