I asked a previous question of this same program. I would like more opinions before I submit this assignment since I edited the program after receiving feedback last time.
public class Room_Dimension
{
//Data fields
private double length;
private double width;
//Constructor
public Room_Dimension(double length, double width)
{
super();
this.length = length;
this.width = width;
}
//Copy constructor
public Room_Dimension(Room_Dimension rd)
{
this.length = rd.getLength();
this.width = rd.getWidth();
}
//Accessors
public double getLength()
{
return length;
}
public double getWidth()
{
return width;
}
//Mutators
public void setLength(double length)
{
this.length = length;
}
public void setWidth(double width)
{
this.width = width;
}
//Function to calculate the area
public double getArea()
{
return length * width;
}
//Function to display information
public String toString()
{
return "Dimensions of room: (length = " + length + ", width = " + width + ")";
}
}
public class Room_Carpet
{
//Data fields
private Room_Dimension rd;
private double carpetCost;
//Constructor
public Room_Carpet(Room_Dimension rd, double carpetCost)
{
super();
this.rd = rd;
this.carpetCost = carpetCost;
}
//Copy constructor
public Room_Carpet(Room_Carpet rc)
{
this.rd = rc.rd;
this.carpetCost = rc.getCarpetCost();
}
//Function to determine total cost of carpet that will fill area
public double getTotalCost()
{
return carpetCost * rd.getArea();
}
//Function to get size
public Room_Dimension getSize()
{
return rd;
}
//Function to get carpet cost
public double getCarpetCost()
{
return carpetCost;
}
//Function to display information
public String toString()
{
return "" + rd + ", Carpet cost per square feet = $" + carpetCost + ", " + "Total cost = $" + getTotalCost() + "";
}
}
public class Carpet_Calculator
{
public static void main(String[] args)
{
// Create a Scanner object for keyboard input.
Scanner keyboard = new Scanner(System.in);
// Display information about program.
System.out.println("This program will display the carpet cost of a room.");
System.out.println("Please enter the following information.");
// Get the length of the room.
System.out.print("Enter the length of room: ");
double length = keyboard.nextDouble();
// Get the width of the room.
System.out.print("Enter the width of room: ");
double width = keyboard.nextDouble();
// Get the cost of price per square feet of the desired carpeting.
System.out.print("Enter the price per square feet for the desired carpeting: ");
double carpetCost = keyboard.nextDouble();
//Close keyboard
keyboard.close();
// Create Room_Dimension and Room_Carpet objects.
Room_Dimension dimension = new Room_Dimension(length, width);
Room_Carpet roomCarpet = new Room_Carpet(dimension, carpetCost);
// Print the object calling the toString
System.out.println(roomCarpet);
}
}