-
Notifications
You must be signed in to change notification settings - Fork 0
/
Movie.java
67 lines (60 loc) · 1.71 KB
/
Movie.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
/** Class to represent a movie
*
* @author Alfred
* @version 1
*/
public class Movie {
/** The name of the movie */
String name;
/** The length in minutes for this movie */
Integer length;
/**
* The constructor for a Movie
* @param name Name of the movie as a String
* @param length In minutes from midnight
*/
public Movie(String name, Integer length) {
this.name = name;
this.length = length;
}
/**
* Turns a string representation of a movie into a Movie
* @param m String representation of a movie
* @return Movie form of the string
* @throws RuntimeException Says the string wasn't formatted
*/
public static Movie fromString(String m) {
String[] w = m.split(":");
Movie wm = new Movie(w[0], Integer.parseInt(w[1]));
return wm;
}
/**
* Overriding equals method for a Movie
* Compares the name of the movie and it's showtime
* @param o to be compared to this Movie
* @return boolean whether this Movie and that Object are equal
*/
public boolean equals(Object o) {
if (o instanceof Movie) {
Movie that = (Movie)o;
return this.hashCode() == that.hashCode();
}
else {
return false;
}
}
/**
* Converts this Movie to a String
* @return String that represents this Movie
*/
public String toString() {
return this.name + ":" + length.toString();
}
/**
* Overriding the hashCode method for a Movie
* @return int the hashCode of this Movie
*/
public int hashCode() {
return this.name.hashCode() + this.length;
}
}