0

I have this condition (property rent system, rent is counted per night)

  1. Owner has one or more property. Property has description, price, and isOccupied attribute.
  2. The property can be: hotel (with 3 room types), flat/apartment, and house for homestay.
  3. Through a registry function, a customer can order one or more property available at certain date.

Here are the pre-defined conditions for registry function:

  1. There are 2 registered owners and customers in the system.
  2. Owner 1 has 10 hotel rooms (standard type) for US$30 per night and 3 hotel rooms (suite type) for US$60 per night.
  3. Owner 2 has 3 apartments for US$70 per night and 5 homestay house for US$20 per night.
  4. Customers can rent one or more owner's property for a certain date.

To model the property, I use inheritance concept. For now, it looks something like this. Property.java

public class Property {
    private String description;
    private int propertyPrice;
    private String ownerName; // should it be here? or should it be made in another class?
    private boolean isOccupied;

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public int getPropertyPrice() {
        return propertyPrice;
    }

    public void setPropertyPrice(int propertyPrice) {
        this.propertyPrice = propertyPrice;
    }
}

Hotel.java

public class Hotel extends Property {
    private String[] roomType;
    private int[] roomCount;
    
    public Hotel(){
        this.roomType = new String[]{"Standard", "Deluxe", "Suite"};
        this.roomCount = new int[]{0, 0, 0};
    }

    public String[] getRoomType() {
        return roomType;
    }

    public void setRoomType(String[] roomType) {
        this.roomType = roomType;
    }

    public int[] getRoomCount() {
        return roomCount;
    }

    public void setRoomCount(int[] roomCount) {
        this.roomCount = roomCount;
    }    
}

Apartment.java

public class Apartment extends Property {
    private int roomCount;

    public int getRoomCount() {
        return roomCount;
    }

    public void setRoomCount(int roomCount) {
        this.roomCount = roomCount;
    }
}

Homestay.java

public class HomestayRoom extends Property {
    private String parentName; 

    public String getParentName() {
        return parentName;
    }

    public void setParentName(String parentName) {
        this.parentName = parentName;
    }
}

What makes me confused is, how can I define the pre-defined conditions for registry to model owner-property relation? Should I make the owner at another class? If so, how can I relate the properties and its owner?

1 Answer 1

2

Most of what you have done is correct, but you could also have a property type enum

public enum PropertyType{
    HOTEL,APARTMENT,HOMESTAY
}

Now you're super class would be

public class Property {
    private String description;
    private int propertyPrice;
    private String ownerName;
    private boolean isOccupied;
    private PropertyType pt;
    ....
    }

A constructor for hotel would be

public Hotel(){
        this.roomType = new String[]{"Standard", "Deluxe", "Suite"};
        this.roomCount = new int[]{0, 0, 0};
        super(PropertyType.HOTEL);
    }

Similarly you could have constructors for Homestay and Apartment, with the extra line of super(PropertyType.HOMESTAY) and super(PropertyType.APARTMENT) respectively.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.