LANGUAGE JAVA Create a New Java Project called YourLastNameC
LANGUAGE: JAVA
Create a New Java Project called YourLastNameCarpetCalculator.
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.
NOTE: Each class should be defined in its on class file.
GRADING RUBRIC
UML Diagram for Carpet Calculator Room Carpet Size ROOmDimension carpetCost double RoomCarpet (dim RoomDimension, cost double) get TotalCost0 double toString0 String Room Dimension length double width double RoomDimension (len double, w double) getArea0 double toString0 StringSolution
import java.util.*;
class RoomDimension
{
private double length;
private double width;
public RoomDimension() //default constructor
{
length = 0.0;
width = 0.0;
}
public RoomDimension(double len,double w) //parameterizd constructor
{
length = len;
width = w;
}
public double getArea() //compute Area
{
return length*width;
}
public String toString()
{
return \"Length = \"+length +\" Width = \"+width +\" Area = \"+getArea();
}
}
class RoomCarpet extends RoomDimension
{
private RoomDimension size; //object of RoomDimension
private double carpetCost;
public RoomCarpet(RoomDimension dim,double cost)
{
size = dim;
carpetCost = cost;
}
public double getTotalCost()
{
return (size.getArea()*carpetCost);
}
public String toString()
{
return \"Total Cost = \" + getTotalCost();
}
}
class LastNameCarpetCalculator
{
public static void main (String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.println(\"Enter length and width of room\");
double length = scan.nextDouble();
double width = scan.nextDouble();
RoomDimension RD = new RoomDimension(length,width);
System.out.println(\"Enter cost of carpet per square foot\");
System.out.println(RD.toString());
double cost = scan.nextDouble();
RoomCarpet RC = new RoomCarpet(RD,cost);
System.out.println(RC.toString());
}
}
output:

