import java.util.*; /* This class defines one property for the game Monopoly and the current state of the property (owner, value, houses, etc.) */ public class Property { //Private instance variables private String name; private int cost; private int mortgageRate; private int houseCost; private int rent; private int house1; private int house2; private int house3; private int house4; private int hotel; //current state variables private String owner = ""; private int currentRent = 0; private int numHouses = 0; private boolean hotelOwned = false; private boolean mortgaged = false; /* input: name, cost, mortgageRate, houseCost, rent for each house 0-4, rent for hotel Precondition: none Postcondition: initialize instance variables for the property */ public Property(String n, int c, int m, int hc, int r, int h1, int h2, int h3, int h4, int h5) { name = new String(n); cost = c; mortgageRate = m; houseCost = hc; rent = r; house1 = h1; house2 = h2; house3 = h3; house4 = h4; hotel = h5; } /* Precondition: initialized instance variables for the property Postcondition: currentRent is set to the correct amount */ private void calculateCurrentRent() { if(mortgaged) currentRent = mortgageRate; else { if(hotelOwned) currentRent = hotel; else { switch(numHouses) { case 0: currentRent = rent; break; case 1: currentRent = house1; break; case 2: currentRent = house2; break; case 3: currentRent = house3; break; case 4: currentRent = house4; break; default: currentRent = rent; } } } //System.out.println("The current rent is " + currentRent); } public void setOwner(String s) { owner = new String(s); } public void setNumHouse(int i) { numHouses = i; } /* Precondition: initialized instance variables for the property Postcondition: hotelOwned set to true and numHouses is 0 */ public void buyHotel() { Scanner s = new Scanner(System.in); hotelOwned = true; numHouses = 0; System.out.print(name + " has a hotel\n"); } /** Precondition: The instance variables of the calling objects have values. Postcondition: The number of houses the user owns have been updated by one if the owner had fewer than 4 houses and the property has not been mortgaged. If the owner had 4 houses, they bought a hotel and now have zero houses. */ public void buyHouse() { Scanner s = new Scanner(System.in); if(!hotelOwned || !mortgaged) { if (numHouses == 4) buyHotel(); if (numHouses < 4) numHouses++; } System.out.print(name + " has " + numHouses + " house(s)\n"); } /* Precondition: initialized instance variables for the property Postcondition: property is mortgaged, has zero houses and no hotel */ public void mortgageProperty() { Scanner s = new Scanner(System.in); mortgaged = true; numHouses = 0; hotelOwned = false; System.out.print(name + " is now mortgaged\n"); } /* Precondition: initialized instance variables for the property Postcondition: mortgaged property is false */ public void payMortgage() { Scanner s = new Scanner(System.in); mortgaged = false; System.out.print(name + " has been unmortgaged\n"); } /* Precondition: initialized instance variables for the property Postcondition: get owner name from user and set to owner */ public void buyProperty() { Scanner s = new Scanner(System.in); System.out.println("Congratulations. You purchased " + name + "\nMay I please have your name?"); owner = s.nextLine(); } /* Precondition: initialized instance variables for the property Postcondition:calculate the rent and return the value */ public int getRent() { calculateCurrentRent(); return currentRent; } /* Precondition: initialized instance variables for the property Postcondition: print property information to the screen */ public void inquire() { Scanner s = new Scanner(System.in); calculateCurrentRent(); System.out.print(name + " is currently owned by " + owner + ", \nhas " + numHouses + " houses"); if(hotelOwned) System.out.print("\nhas a hotel, \n"); else System.out.print("\ndoes not have a hotel, \n"); if(mortgaged) System.out.print("is mortgaged, \n"); else System.out.print("is not mortgaged, \n"); System.out.println("and the current rent is " + currentRent); } }