This repository was archived by the owner on Nov 30, 2021. It is now read-only.
  
  
  - 
                Notifications
    You must be signed in to change notification settings 
- Fork 0
Residence
        Matthew Pohlmann edited this page Jan 1, 2014 
        ·
        1 revision
      
    ####Description A general residence in SimCity201. Inhabited by a Resident and potentially administered by a Landlord.
####Class Signature
public class Residence extends Structure {}####Data
Resident resident;
List<Food> fridge;
boolean hasFood;
Role owner; // either a landlord or a residentclass Food {
	String type;
	int amount;
	public Food(String t, int amt) {
		type = t;
		amount = amt;
	}
	public void addMore(int amt) {
		amount += amt;
	}
	public void minusOne() {
		amount--;
	}
	public boolean noneLeft() {
		if (amount==0) {
			return true;
		}
	}
        public String getType(){
			return type;
	}
	public int getAmount(){
			return amount;
	}
}####Constructors
public Residence(int x, int y, int width, int height, int id) {
    super(x, y, width, height, id);
    owner = NULL;
    resident = NULL;
}####Methods
public void setOwner(Role p) {
	owner = p;
}public void setResident(Resident r) {
	resident = r;
}public void removeResident(Resident r) {
	if(resident == r) {
                resident = NULL;
        }
}public boolean hasFood() {
	return hasFood;
}public void addFood(String t, int amt) {
	if Ǝ Food f in  fridge ∋ f.getType() == t then,
		f.addMore(amt);
	Food f = new Food(t, amt);
	fridge.add(f);
	hasFood = true;
}public void removeFood(String t) {
	if Ǝ Food f in  fridge ∋ f.getType() == t then, {
		f.minusOne();
		if (f.noneLeft()) {
			fridge.remove(f);
			if (fridge.empty()) {
				hasFood = false;
			}
		}
	}
}public void performMaintenance() {
	//perform maintenance actions
}public Resident getResident() {
	return resident;
}public Role getOwner() {
	return owner;
}public boolean isApartment() {
	return owner!=resident;
}