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

Create a New Java Project called YourLastNameCarpetCalculator . (please include

ID: 3871419 • Letter: C

Question

Create a New Java Project called YourLastNameCarpetCalculator. (please include comments so i can understand)

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. (12 X 10 X 8 = 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. (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 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 figure below is a UML diagram 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.

Continuously prompt the user for input until the user chooses to end the program.

Input Validation: Do not accept unreasonable/junk values, or negative values, which must be rejected and asked for another one.

NOTE: Each class should be defined in its on class file.

UML Diagram for Carpet Calculator

RoomCarpet size : RoomDimension carpetCost : double + RoomCarpet(dim : RoomDimension, + getTotalCost) : double cost: double) + toString0: String RoomDimensiorn length: double width: double +RoomDimensionlen: double, + getArea) : double w : double) + toString) : String

Explanation / Answer

RoomDimension.java

public class RoomDimension {
// Declaring instance variables
private double length;
private double width;

// Parameterized constructor
public RoomDimension(double length, double width) {
super();
this.length = length;
this.width = width;
}

// getters
public double getLength() {
return length;
}

public double getWidth() {
return width;
}

// Calculate the area of the room
public double areaOfRoom() {
return getLength() * getWidth();

}

}

_________________

RoomCarpet.java

public class RoomCarpet {
// Declaring instance variable
private double cost_of_carpet;

// Creating RoomDimension class type variable
RoomDimension roomdimension;

// parameterized constructor
public RoomCarpet(double cost_of_carpet, RoomDimension roomdimension) {
super();
this.cost_of_carpet = cost_of_carpet;
this.roomdimension = roomdimension;
}

// Getter method
public double getCost_of_carpet() {
return cost_of_carpet;
}

// Method which calculate the total cost of carpet
public double totalCostOfCarpet() {
return getCost_of_carpet() * roomdimension.areaOfRoom();
}

}

______________________

DriverClass.java

import java.util.Scanner;

public class DriverClass {

public static void main(String[] args) {

//Declaring variables

double length, width, carpetCostPerFt, total_carpet_cost;

//Scanner object is used to get the inputs entered by the user

Scanner sc = new Scanner(System.in);

while (true) {

//Getting the length of the carpet

System.out.print("Enter the Length of the Carpet (in feet):");

length = sc.nextDouble();

if (length < 0) {

System.out.println("** Invalid.Must be Positive **");

continue;

} else

break;

}

while (true) {

//Getting the width of the carpet

System.out.print("Enter the Width of the Carpet (in feet):");

width = sc.nextDouble();

if (width < 0) {

System.out.println("** Invalid.Must be Positive **");

continue;

} else

break;

}

while (true) {

//Getting the cost of the carpet per feet

System.out.print("Enter cost of Carpet (per sq ft) :$");

carpetCostPerFt = sc.nextDouble();

if (carpetCostPerFt < 0) {

System.out.println("** Invalid.Must be Positive **");

continue;

} else

break;

}

/* Creating the Room Dimension class object

* by passing the length and width as arguments

*/

RoomDimension dimension = new RoomDimension(length, width);

//Creating the Room Carpet class object

RoomCarpet roomcarpet = new RoomCarpet(carpetCostPerFt, dimension);

//Calling the method which calculates the total cost of the carpet

total_carpet_cost = roomcarpet.totalCostOfCarpet();

//Displaying the total cost of the carpet

System.out.println("Total of cost of carpet is :$" + total_carpet_cost);

}

}

________________________

Output:

Enter the Length of the Carpet (in feet):-12
** Invalid.Must be Positive **
Enter the Length of the Carpet (in feet):12
Enter the Width of the Carpet (in feet):-10
** Invalid.Must be Positive **
Enter the Width of the Carpet (in feet):10
Enter cost of Carpet (per sq ft) :$8
Total of cost of carpet is :$960.0

_____________Could you rate me well.Plz .Thank You