Question: Write a test program of this code to ask the user to enter the length, width, and the price per square foot of the a

Write a test program of this code to ask the user to enter the length, width, and the price per square foot of the a carper. Then display the total cost of the carpet. Total Cost = (length*breath)/price of square foot. Create a toString function to display the area of the carpet as well.

I used the diagram below as reference

Write a test program of this code to ask the user to//RoomDimension class class RoomDimension { //two private field for length and breadth private double lenght; private double width; //Constructor for creating object with length and width public RoomDimension(double length, double width){ this.lenght = length; this.width = width; } //It will return Area of Room public double getAreaOfRoom(){ return lenght*width; }

}

//Room Carpet Class class RoomCarpet { //Room dimension object and cost per sqt o carpet private RoomDimension roomDimension; private double costOfCarperPerSqrFeet; //constructor for crating object with object o room dimension and cost //per sqr feet of carpet public RoomCarpet(RoomDimension roomDimension, double costPerCarpetPerSqr){ this.roomDimension = roomDimension; this.costOfCarperPerSqrFeet = costPerCarpetPerSqr; } //Public method for displaying total cost public double getTotalCost(){ return roomDimension.getAreaOfRoom()*costOfCarperPerSqrFeet; } }

RoomCarpet |- size : Room Dimension |- carpetCost : double + RoomCarpet(dim : RoomDimension, cost : double) + get TotalCost(): double + toString(): String Room Dimension - length : double - width : double + Room Dimension(len: double, w: double) + getArea(): double + toString(): String

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!