-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTicket.java
53 lines (49 loc) · 1.28 KB
/
Ticket.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
/**
* Class to represent a Ticket
* @author Alfred Ababio
* @version 2
*
*/
public class Ticket {
/** String to represent the name of the type of Ticket */
String name;
/** Integer to represent the price for this ticket */
Integer price;
/**
* Constructor for a Ticket
* @param name The name of this ticket type
* @param price The price for this ticket
*/
Ticket(String name, Integer price) {
this.name = name;
this.price = price;
}
/**
* Overridden equality method for Tickets
* @param o Object to be compared against this Ticket
* @return boolean if this and o are equal
*/
public boolean equals(Object o) {
if (o instanceof Ticket) {
Ticket that = (Ticket)o;
return this.hashCode() == that.hashCode();
}
else {
return false;
}
}
/**
* Turns this Ticket into a String
* @return String representation of this ticket
*/
public String toString() {
return this.name + ":" + this.price.toString();
}
/**
* Turns this Ticket into its hashCode
* @return int hashCode of this String
*/
public int hashCode() {
return this.name.hashCode() + this.price;
}
}