import java.util.Scanner;
class Room_Dimension
{
private double length;
private double width;
public Room_Dimension(double length, double width)
{
this.length = length;
this.width = width;
}
public void setLength(double length)
{
this.length = length;
}
public void setWidth(double width)
{
this.width = width;
}
public double getLength()
{
return length;
}
public double getWidth()
{
return width;
}
public Room_Dimension(Room_Dimension roomDimensions)
{
this.length = roomDimensions.getLength();
this.width = roomDimensions.getWidth();
}
public double getArea()
{
return length * width;
}
}
class Room_Flooring
{
private String floorMaterial;
private Room_Dimension roomDimensions;
private double cost_of_material;
public Room_Flooring(Room_Dimension roomDimensions, String floorMaterial)
{
this.roomDimensions = roomDimensions;
this.floorMaterial = floorMaterial;
this.cost_of_material = cost_of_material;
}
public Room_Dimension getSize()
{
return roomDimensions;
}
public void setFloorMaterial(String floorMaterial)
{
this.floorMaterial = floorMaterial;
}
public String getFloorMaterial()
{
return floorMaterial;
}
public double getCost_of_Material(String floorMaterial)
{
if (floorMaterial == "NormalTile")
{
cost_of_material = 2.0;
}
if (floorMaterial == "FancyTile")
{
cost_of_material = 4.0;
}
return cost_of_material;
}
public Room_Flooring(Room_Flooring roomFlooring)
{
this.roomDimensions = roomFlooring.roomDimensions;
this.floorMaterial = roomFlooring.getFloorMaterial();
this.cost_of_material = roomFlooring.getCost_of_Material(floorMaterial);
}
public double getTotalCost()
{
return (getCost_of_Material(floorMaterial)) * roomDimensions.getArea();
}
public String toString()
{
return ""+ getTotalCost() +"" ;
}
}
public class Pricing
{
public static void main(String[] args)
{
System.out.print('\u000C');
Scanner room = new Scanner(System.in);
// Get the length of the room.
System.out.println("Enter the length of room: ");
double length = room.nextDouble();
// Get the width of the room.
System.out.println("Enter the width of room: ");
double width = room.nextDouble();
System.out.println("Enter the floor material that you want- NormalTile or FancyTile: ");
String floorMaterial = room.nextLine();
// Create Room_Dimension and Room_Flooring objects.
Room_Dimension dimensions = new Room_Dimension(length, width);
Room_Flooring roomFlooring = new Room_Flooring(dimensions, floorMaterial);
// Print the object calling the toString
System.out.println(roomFlooring);
}
}
guffadi 0 Newbie Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.