Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Use variables instead of hardcoded values. 2.Add comments and format your program properly i.e. indentation, etc I need help with my java code. I use
- Use variables instead of hardcoded values.
2.Add comments and format your program properly i.e. indentation, etc
I need help with my java code. I use java on BlueJ. Thanks!!!
Carpet Calculator Note: This assignment is #3 in Programming Challenges section of the chapter. See additional requirement below for input validation and cost formatting. 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 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. (12x10x8=960.) First, you should create a class named Room Dimension that has two fields: one for the length of the room and one for the width. The Room Dimension class should have a method that returns the area of the room. (The area of the room is the room's length multiplied by the room's width.) Next you should create a RoomCarpet class that has a Room Dimension 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. Additional requirements: 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. 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: 20.00 Width: 15.00 Price: 8.50 Area: 300.00 Carpet cost: $2,550.00 RoomCarpet - size : Room Dimension - carpetCost : double + RoomCarpet(dim : Room Dimension, cost : double): + getTotalCost(): double + toString(): String Room Dimension - length : double - width : double + RoomDimension(len : double, w: double): + getArea(): double + toString(): StringStep 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