Question

In: Computer Science

Flooring Quote Calculator Create a program that calculates a price quote for installing different types of...

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:

  • Two fields, all private
    • area - A double that represents the square footage of the room.
    • floorType - A FloorType object that represents the type of flooring chosen for the room.
  • One constructor, public
    • Accepts two arguments, parameters named areaIn (double) and floorTypeIn (FloorType)
    • Assigns the parameter’s values to their respective fields.
  • Two Methods, both public
    • Getters for both fields

House Class (House.java)

This class must contain only the following:

  • Eight fields, all private
  • ownerName - A String for holding the homeowner’s name.
  • phoneNumber - A String for holding the homeowner’s phone number.
  • streetAddress - A String for holding the house’s street address.
  • city - A String for holding the house’s city.
  • state - A String for holding the house’s state.
  • zipCode - A String for holding the house’s zip code.
  • rooms - An array of Room objects.
  • roomIndex - An int that keeps track of what index to place new Room objects in the rooms array.
  • One constructor, public
    • Accepts one argument- numRooms
    • The numRooms argument is used to instantiate the rooms field with an array of the provided length (numRooms).
    • Assigns empty Strings to the other six fields and assigns zero to roomIndex.
  • Fifteen Methods, both public
    • Setters and getters for only the ownerName, phoneNumber, streetAddress, city, state, and zipCode fields (12 methods total, all public)
    • addRoom (public, returns void)
      • Accepts two arguments, parameters named sqft (double) and fType (FloorType object)
        • “sqft” represents the square footage of the room.
        • fType is an enumerator object. The FloorType class that contains the enumerator is provided. It’s in its own class so all classes for the assignment can use it.
      • The method should use the parameters to instantiate a Room object and add it to the next available index in the array (using the roomIndex field).
      • Remember to increment roomIndex after placing the Room object in the array.
    • getInstallationCost(public, returns double, no parameters)
      • This method calculates and returns the total close of installation.
      • The cost is $10.00 per square foot, regardless of flooring type.
      • You’ll need to use the Room objects in the rooms field to complete this.
    • getFlooringCost(public, returns double, no parameters) ▪ This method calculates and returns the total cost of flooring.
      • Carpet is $7.00 per square foot
      • Tile is $5.00 per square foot
      • Hardwood is $6.00 per square foot
      • You’ll need to use the Room objects in the rooms field to complete this.
  • *****************************************CODE BELOW****

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;
       }

   }

}

Solutions

Expert Solution

/************************************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 :)


Related Solutions

Create a small program that calculates the final grade in this course, given the different assignments...
Create a small program that calculates the final grade in this course, given the different assignments and exams you will be required to take. The program should ask for all the grades through the semester, and as a final output it should compute the weighted average as well as give the final letter grade. You should use the syllabus for this course to calculate the final grade. • Five assignments worth 30 points each. • Three projects worth 100 points...
Change Calculator Task: Create a program that will input a price and a money amount. The...
Change Calculator Task: Create a program that will input a price and a money amount. The program will then decide if there is any change due and calculate how much change and which coins to hand out. Coins will be preferred in the least number of coins (starting with quarters and working your way down to pennies). Input: total_price, amount_tender allow the user to input 'q' for either value if they want to quit the program Validate: total_price cannot be...
Using Loops for the Hotel Occupancy calculator. You will write a program that calculates the occupancy...
Using Loops for the Hotel Occupancy calculator. You will write a program that calculates the occupancy of a hotel. Rules: 1# The hotel must have more than 2 floors and less than or equal 5 floors. 2# Each floor in the hotel can have a different number of rooms on the floor. 3# You must set the number of occupied rooms. Again, there must less rooms occupied than the number of rooms. 4# Using the total number of rooms and...
DESIGH A FLOWCHART IN FLOWGORITHM Speeding Violation Calculator. Design a program that calculates and displays the...
DESIGH A FLOWCHART IN FLOWGORITHM Speeding Violation Calculator. Design a program that calculates and displays the number of miles per hour over the speed limit that a speeding driver was doing. The program should ask for the speed limit and the driver's speed. Validate the input as follows: The speed limit should be at least 20, but not greater than 70. The driver's speed should be at least the value entered for the speed limit (otherwise the driver was not...
Create a program in java that calculates area and perimeter of a square - use a...
Create a program in java that calculates area and perimeter of a square - use a class and test program to calculate the area and perimeter; assume length of square is 7 ft.
In this project you will create a basic console based calculator program. The calculator can operate...
In this project you will create a basic console based calculator program. The calculator can operate in two modes: Standard and Scientific modes. The Standard mode will allow the user to perform the following operations: (+, -, *, /) add, subtract, multiply, and divide The Scientific mode will allow the user to perform the same functionality as the Standard add, subtract, multiply, and divide (+, -, *, / ) plus the following: sin x, cos x, tan x. (sin x,...
In C Program #include Create a C program that calculates the gross and net pay given...
In C Program #include Create a C program that calculates the gross and net pay given a user-specified number of hours worked, at minimum wage. The program should compile without any errors or warnings (e.g., syntax errors) The program should not contain logical errors such as subtracting values when you meant to add (e.g., logical errors) The program should not crash when running (e.g., runtime errors) When you run the program, the output should look like this: Hours per Week:...
Create the pseudocode solution to a program that calculates the final score and letter grade for...
Create the pseudocode solution to a program that calculates the final score and letter grade for one student. Please use the following grading system: 9 Homework Assignments – 100 points each 10 points 11 Quizzes – 100 points each 5 points 5 Projects – 100 points each 10 points 6 Discussion posts – 100 points each 10 points 4 Exams – 100 points each 65 points A = 90 – 100% B = 80 – 89% C = 70 –...
In java. Prefer Bluej Create a program in java that calculates area and perimeter of a...
In java. Prefer Bluej Create a program in java that calculates area and perimeter of a square - use a class and test program to calculate the area and perimeter; assume length of square is 7 ft.
Modify the provided code to create a program that calculates the amount of change given to...
Modify the provided code to create a program that calculates the amount of change given to a customer based on their total. The program prompts the user to enter an item choice, quantity, and payment amount. Use three functions: • bool isValidChoice(char) – Takes the user choice as an argument, and returns true if it is a valid selection. Otherwise it returns false. • float calcTotal(int, float) – Takes the item cost and the quantity as arguments. Calculates the subtotal,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT