Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The westfield carpet company has asked you to write an application that calculat

ID: 3621030 • Letter: T

Question

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 RoomDimension that has two FeetInches objects as attributes: one for the length of the room and one for the width. The RoomDimension class should have a member function that returns the area of the room as a FeetInches object.
Next, you should create a RoomCarpet class that has a RoomDimension object as an attribute. It should also have an attribute for the cost of the carpet per square foot. The RoomCarpet class should have a member function that returns the total cost of the carpet.
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.

Explanation / Answer

Dear, Here is the code.. Room Dimension class public class RoomDimension { private int roomLength=0; private int roomWidth=0; public void setRoomLength(int roomlength) { this.roomLength = roomlength; } public void setRoomWidth(int roomwidth) { this.roomWidth = roomwidth; } public RoomDimension() { } public int getRoomArea() { return roomLength*roomWidth; } } RoomCarpet class public class RoomCarpet { private RoomDimension thisRoomDimension; final int carpetUnitCost=8; public void setRoomDimension(RoomDimension thisroomdimension) { this.thisRoomDimension = thisroomdimension; } public int getTotalAMount() { return thisRoomDimension.getRoomArea()* carpetUnitCost; } } Class to test these two classes import java.io.*; import java.util.Scanner; public class CarpetCalculator { public static void main(String[] args) { int roomLength; int roomWidth; //Create Scanner object Scanner keyboard= new Scanner(System.in); System.out.println("Enter The Length Of The Room"); roomLength= keyboard.nextInt(); System.out.println("Enter The Width Of The Room"); roomWidth = keyboard.nextInt(); RoomDimension roomd = new RoomDimension(); roomd.setRoomLength(roomLength); roomd.setRoomWidth(roomWidth); //instantiating carpet class RoomCarpet room1 = new RoomCarpet(); //function call to set dimensions room1.setRoomDimension(roomd); //displaying data System.out.println("Room dimensions: "); System.out.println("Length: " + roomLength + " Width: " + roomWidth + " Area: " + room1.getRoomArea()); System.out.println("Carpet cost:$" + room1.getTotalAMount()); //Exit program System.exit(0); }//end main function }//end class Hope this will help you..