In: Computer Science
Flooring Quote Calculator
Create a program that calculates a price quote for installing different types of flooring in a house.
Allows the user to enter the homeowner’s information, number of rooms where they want new flooring installed, the area of each room, and the type of flooring for each room. Your program will then calculate and print the installation costs.
Need to use a House class that contains information about the home and home owner. An inner class, Room, will maintain the dimension and flooring options selected. The House object will maintain an array of Room objects.
Room Class (Inner Class in House.java)
must contain only the following:
House Class (House.java)
This class must contain only the following:
package house;
public class House {
/*
* Private data field
*/
private String ownerName;
private String phoneNumber;
private String streetAddress;
private String city;
private String state;
private String zipcode;
private Room[] rooms;
private int roomIndex;
// constructor
public House(int numRooms) {
rooms = new
Room[numRooms];
this.ownerName = "";
this.phoneNumber = "";
this.streetAddress = "";
this.city = "";
this.state = "";
this.zipcode = "";
this.roomIndex = 0;
}
// getter and setter
public String getOwnerName() {
return ownerName;
}
public void setOwnerName(String ownerName) {
this.ownerName = ownerName;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber)
{
this.phoneNumber =
phoneNumber;
}
public String getStreetAddress() {
return streetAddress;
}
public void setStreetAddress(String streetAddress)
{
this.streetAddress =
streetAddress;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getZipcode() {
return zipcode;
}
public void setZipcode(String zipcode) {
this.zipcode = zipcode;
}
// add room
public void addRoom(double sqft, FloorType floorType)
{
rooms[roomIndex] = new
Room(sqft, floorType);
roomIndex++;
}
// installation cost
public double getInstallationCost() {
double installationCost = 0;
for (Room room : rooms) {
installationCost += room.getArea() * 10.00;
}
return installationCost;
}
// flooring cost
public double getFlooringCost() {
double flooringCost = 0;
for (Room room : rooms) {
if (room.getFloorType() == FloorType.CARPET) {
flooringCost += room.getArea() * 7.00;
} else if
(room.getFloorType() == FloorType.TILE) {
flooringCost += room.getArea() * 5.00;
} else if
(room.getFloorType() == FloorType.HARDWOOD) {
flooringCost += room.getArea() * 6.00;
}
}
return flooringCost;
}
// enum FloorType
enum FloorType {
CARPET, TILE, HARDWOOD
}
// class Room
class Room {
private double area;
private FloorType floorType;
public Room(double area,
FloorType floorType) {
super();
this.area =
area;
this.floorType =
floorType;
}
public double getArea() {
return
area;
}
public FloorType getFloorType()
{
return
floorType;
}
}
}
/************************************FlooringQuoteCalculator.java******************************/
package house;
import java.util.Scanner;
import house.House.FloorType;
// TODO: Auto-generated Javadoc
/**
* The Class FlooringQuoteCalculator.
*/
public class FlooringQuoteCalculator {
/**
* The main method.
*
* @param args the arguments
*/
public static void main(String[] args) {
Scanner scan = new
Scanner(System.in);
String cont = "";
do {
System.out.print("Enter House owner name: ");
String
houseOwner = scan.nextLine();
System.out.print("Enter Phone number: ");
String number =
scan.nextLine();
System.out.print("Enter Street Address: ");
String
streetAddress = scan.nextLine();
System.out.print("Enter City: ");
String city =
scan.nextLine();
System.out.print("Enter State: ");
String state =
scan.nextLine();
System.out.print("Enter Zipcode: ");
String zipcode =
scan.nextLine();
System.out.print("How many number of rooms you want: ");
int
numberOfRooms = scan.nextInt();
House house = new House(numberOfRooms);
house.setOwnerName(houseOwner);
house.setPhoneNumber(number);
house.setStreetAddress(streetAddress);
house.setCity(city);
house.setState(state);
house.setState(state);
house.setZipcode(zipcode);
for (int i = 0; i < numberOfRooms; i++) {
System.out.print("Enter area of Room " + (i + 1)
+ "in sqft: ");
double area = scan.nextDouble();
scan.nextLine();
System.out.print("Enter Floor type: ");
String floorType = scan.nextLine();
if (floorType.equalsIgnoreCase("Carpet")) {
house.addRoom(area,
FloorType.CARPET);
} else if (floorType.equalsIgnoreCase("Tile"))
{
house.addRoom(area,
FloorType.TILE);
} else if
(floorType.equalsIgnoreCase("Hardwood")) {
house.addRoom(area,
FloorType.HARDWOOD);
}
}
System.out.println("Installation Cost: " +
house.getInstallationCost());
System.out.println("Flooring Cost: " +
house.getFlooringCost());
System.out.print("Do you want to calculate cost of another
house(Y/N): ");
cont =
scan.nextLine();
} while
(!cont.equalsIgnoreCase("N"));
scan.close();
}
}
/**********************output***************************/
Enter House owner name: Virat
Enter Phone number: 346574
Enter Street Address: JK Street
Enter City: Jp
Enter State: RJ
Enter Zipcode: 945674
How many number of rooms you want: 2
Enter area of Room 1in sqft: 345
Enter Floor type: Tile
Enter area of Room 2in sqft: 3443
Enter Floor type: CARPET
Installation Cost: 37880.0
Flooring Cost: 25826.0
Do you want to calculate cost of another house(Y/N): Y
Enter House owner name: JKS
Enter Phone number: 454353
Enter Street Address: MS
Enter City: JP
Enter State: RJ
Enter Zipcode: 9875633
How many number of rooms you want: 3
Enter area of Room 1in sqft: 343
Enter Floor type: TILE
Enter area of Room 2in sqft: 454
Enter Floor type: HARDWOOD
Enter area of Room 3in sqft: 343
Enter Floor type: CARPET
Installation Cost: 11400.0
Flooring Cost: 6840.0
Do you want to calculate cost of another house(Y/N): N
Please let me know if you have any doubt or modify the answer, Thanks :)