-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTheater.java
75 lines (69 loc) · 2.07 KB
/
Theater.java
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
/** Class to represent a movie theater
* @author Alfred Ababio
* @version 2
*/
public class Theater {
/** Name of this theater */
String name;
/** How many seats this theater has */
Integer seatsMax;
/** How many seats this showing has left */
Integer seatsLeft;
/** Constructor for a Theater
*
* @param name The name of this theater
* @param seats The max number of seats theater can fill
*/
public Theater(String name, Integer seats) {
this.name = name;
this.seatsMax = seats;
this.seatsLeft = seats;
}
/** Second constructor for a Theater
* @param t Theater to make this Theater to match
*/
public Theater(Theater t) {
this.name = t.name;
this.seatsMax = t.seatsMax;
this.seatsLeft = t.seatsMax;
}
/**
* Converts a String to a Theater if it is formatted correctly
* @param t String that is formatted as a theater
* @return Theater if the String is formatted correctly
* @throws RuntimeException Says the string wasn't formatted
*/
public static Theater fromString(String t) {
String[] w = t.split(":");
Theater wt = new Theater(w[0], Integer.parseInt(w[1]));
return wt;
}
/**
* Overriding the equals method
* @param o Object to be compared to this Theater
* @return boolean says whether this was equal to that
*/
public boolean equals(Object o) {
if (o instanceof Theater) {
Theater that = (Theater)o;
return this.hashCode() == that.hashCode();
}
else {
return false;
}
}
/**
* Turns this Theater into a String
* @return String representation of this Theater
*/
public String toString() {
return this.name + ":" + this.seatsLeft.toString();
}
/**
* Overriding hashCode because I overrode equals
* @return int that is the hashCode of this Theater
*/
public int hashCode() {
return this.name.hashCode() + this.seatsMax;
}
}