forked from jcrouser/CSC120-A8
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHouse.java
More file actions
110 lines (91 loc) · 2.96 KB
/
House.java
File metadata and controls
110 lines (91 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/* This is a stub for the House class */
import java.util.ArrayList;
public class House extends Building{
boolean hasElevator;
boolean hasDiningRoom;
ArrayList <String> residents;
/**
*
* @param name name of house
* @param address address of house
* @param nFloors numbers of floor in house
* @param hasElevator confirms if house has elevator
* @param hasDiningRoom confirms if house has dining room
*/
public House(String name, String address, int nFloors, boolean hasElevator, boolean hasDiningRoom) {
// this is what "extends building" is refering to
super(name, address, nFloors); // this is a Building
//... with:
this.hasElevator= hasElevator;
this.hasDiningRoom= hasDiningRoom;
this.residents= new ArrayList<String>();
}
/* Overloaded constructor with address only */
public House(String address) {
this(); // Call default constructor
this.address = address; // Override address
}
/* Overloaded constructor with name, address */
public House(String name, String address) {
super(name, address); // Call full constructor with hard-coded # floors
}
// moveIn and moveOut methods
/**
*
* @param name name of house
*/
public void moveIn(String name){
this.residents.add(name); //adding resident to the house
}
public String moveOut(String name){
this.residents.remove(name); //removing resident from the house
return name;
}
// Checking if resident is in 'House'
/**
*
* @param person addressing the person that lives in the house
* @return whether this 'person' lives in the house or not
*/
public boolean isResident(String person){
if(this.residents.contains(name)){
System.out.println(name + "is a resident in this house.");
return true;}
else{
System.out.println(name + "is not a resident in this house.");
return false;
}
}
// if the house has an elevator
public void goToFloor(int floorNum) {
super.goToFloor(floorNum);
if (this.hasElevator == true){
System.out.println("You are now on " + floorNum + ".");
}
else{
System.out.println("Cannot go to " + floorNum + " without an elevator. Sorry.");
}
}
// special case
public void showOptions() {
System.out.println("Available options at " + this.name + ":\n + enter() \n + exit() \n + goUp() \n + goDown()\n + goToFloor(n)");
}
public String toString(){
String description = super.toString();
description = "There are currently " + this.nResidents() + " people living in this house.";
if (this.hasDiningRoom == true){
description = "This house has an active dining room.";
}
else{
description = "This house does not have an active dining room";
}
return description;
}
//main
public static void main(String[] args) {
House myHouse= new House("Comstock House", "1 Manning Rd", 3, true, true);
myHouse.moveIn("Jo");
myHouse.moveIn("Jade");
myHouse.moveIn("Em");
}
}