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: 3635712 • 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 areas of the floor (width times length) by the price per square foot of carpet.

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. (The area of the room if the room's length multiplied by the room's width)

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.

The application should display the total cost of the carpet

Explanation / Answer

Dear User, import java.io.*; import java.util.Scanner; 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; } } class RoomCarpet { private RoomDimension thisRoomDimension; final int carpetUnitCost=8; public void setRoomDimension(RoomDimension thisroomdimension) { this.thisRoomDimension = thisroomdimension; } public int getTotalAMount() { return thisRoomDimension.getRoomArea()* carpetUnitCost; } } public class CarpetCalculator { public static void main(String[] args) { int roomLength; int roomWidth; 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); RoomCarpet room1 = new RoomCarpet(); room1.setRoomDimension(roomd); System.out.println("Room dimensions: "); System.out.println("Length: " + roomLength + " Width: " + roomWidth + "Area: " + room1.getRoomArea()); System.out.println("Carpet cost:$" + room1.getTotalAMount()); System.exit(0); } }