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

C++ programming Please comment your code. The Westfield carpet company has asked

ID: 3556786 • Letter: C

Question

C++ programming

Please comment your code.

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 time's length) by the price per square foot carpet. 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's length multiplied by the room's width.) Next, you should create a RoomCarpet clas 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. Figure 9-21 is a UML diagram that shows possible class designs and the relationship 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 prices per square foot of the desired carpeting. THE application should display the total cost of the carpet.

Explanation / Answer

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;

}

}

private RoomDimension thisRoomDimension;

final int carpetUnitCost=8;

public void setRoomDimension(RoomDimension thisroomdimension)

{

this.thisRoomDimension = thisroomdimension;

}

public int getTotalAMount()

{

return thisRoomDimension.getRoomArea()* carpetUnitCost;

}

}

{

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);

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote