Enums


Enums

Month enumeration
Date class using Month
MonthHarness
Weekday class with enums

Read chapters 6, 7,8, 9.


Classwork


Part A

Create an enumeration AptType representing several different types of apartment. Each type of apartment has a description, a size (square footage), and a rent amount. In the enumeration, provide public final instance variables for these. Also write a parameterized constructor that sets the values of these variables (doing this is just part of setting up the enum) The apartment types are

  description size (sq ft) rent ($/mo)
studio "Studio" 520 480
one bedroom "1 Bedroom" 810 720
two bedroom "2 Bedroom" 1120 1030
luxury "Luxury" 1720 1780

Create the possible values for the enumeration, one for each type of apartment, in this order. Give these brief all-caps names.


Part B

Create a class Apartment. Each Apartment has an instance variable to store its apartment type (use your enumeration).   Also add a boolean indicating whether it is rented or not. Apartments should start off unrented.

Add a private static final variable building in Apartment, which is a 2-dimensional array of Apartments.

Add a constant  FLOORS, which is 10, and another APTSPERFLOOR, which is the number of types of apartment in the enum.   We only need one of each of these for the whole class, and they will be availble to other classes

☑ In the static block, set up building to be FLOORS x APTSPERFLOOR apartments in size, and fill in all the apartments so that there is one apartment with each type on each floor, in the same order as the types were defined.  To do this, use the .values() method of the enumeration so you can  get the appropriate type of apartment for the position on the floor without having to use a conditional. 

Add a static method rent(floor, num) which, if the apartment at that position in building is currently free, sets it as rented and (using the values from AptType) prints a message like

You are renting a 1120 square foot 2 Bedroom apartment for $1030 / month.  Welcome to our building.

If the apartment is already rented, print an apologetic message saying the apartment is taken.

If the number requested is not valid in building (e.g., 15th floor) print an error message.


Part C

In a class with a main,check that you can choose an apartment of each type from the building and rent it, but if you try to rent it again, you get an apology.  Do this without ever creating a new Apartment in main.