Answer:
class RoomDimension
{
double length;
double width;
public RoomDimension(double len, double w)
{
length = len;
width = w;
}
public double getLength()
{
return length;
}
public double getWidth()
{
return width;
}
public double getArea()
{
return length * width;
}
public String toString()
{
String output;
output = "Room dimensions:\\Length: " + length + "\\Width: " + width + "\\Area: " + getArea();
return output;
}
}
And the code for RoomCarpet.java:
class RoomCarpet //extends RoomDimension
{
RoomDimension size;
double carpetCost;
public RoomCarpet(RoomDimension dim, double cost)
{
size = new RoomDimension(dim.getLength(), dim.getWidth());
carpetCost = cost;
}
public double getTotalCost()
{
return carpetCost;
}
public String toString()
{
String output = size + "\\Carpet cost: $" + carpetCost * size.getArea();
return output;
}
}