Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please provide a code in Java Assignment Description The Westfield Carpet Company has asked you to write an application that calculates the price of carpeting

please provide a code in Java

Assignment Description

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 by the price per square foot of carpet. For example, the area of 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. (12108=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. 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 returns the total cost of the carpet.

See a UML diagram (on next page) that shows possible class designs and the relationships among the classes. Once you have written these classes, use them in an application that asks the user to enter the dimensions of a room and the price per square foot of the desired carpeting. The application should display the total cost of the carpet.

Create three java files for this assignment, Room Dimension, Room Carpet, and the program driver.

Validate length, width, and price input from the user. The length, width and price should be more than 0. If the input is invalid, do not exit the program until the user has entered valid input. If one of the inputs is invalid, ask the user to re-enter that input only and keep the other valid inputs intact. The input can be decimal for all three. Format the total cost to two decimal places and put $ in front of it and comma as thousand separator.

Sample output:

Room dimensions: Length: Width:

Price: Area: Carpet cost:

UML diagram:

image text in transcribed

Helpful Note:

Always design your program and desk check it to save time in coding and debugging. One design tool is to write the program in pseudocode i.e. in plain English and when the logic looks good after desk checking it, then start converting it in to Java.

Additional Notes/Requirements:

Use variables instead of hardcoded values.

Add comments and format the program properly.

\begin{tabular}{|l|} \hline \multicolumn{1}{|c|}{ RoomCarpet } \\ \hline - size : RoomDimension \\ - carpetCost : double \\ \hline + RoomCarpet(dim : RoomDimension, \\ cost : double) : \\ + getTotalCost() : double \\ + toString() : String \\ \hline \end{tabular} \begin{tabular}{|l|} \hline \multicolumn{1}{|c|}{ RoomDimension } \\ \hline - length : double \\ - width : double \\ \hline + RoomDimension(len : double, \\ w : double) : \\ + getArea() : double \\ + toString() : String \\ \hline \end{tabular}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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_2

Step: 3

blur-text-image_3

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

SQL Server T-SQL Recipes

Authors: David Dye, Jason Brimhall

4th Edition

1484200616, 9781484200612

More Books

Students also viewed these Databases questions

Question

Explain global human resource management.

Answered: 1 week ago