-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPerformance.java
113 lines (98 loc) · 3.21 KB
/
Performance.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
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
111
112
113
package tss;
import tss.Time;
public class Performance {
/**
* Create a performance object with the specified artist, start time
* of the performance and duration of the performance
* @param artist The artist object for this performance
* @param startTime The start time and date of the performance
* @param duration How long the performance is going to last in minutes
*/
/**
* Reference to the artist that this performance is scheduled for.
*/
private Artist _artist;
/**
* The duration of the performance.
*/
private int _duration;
/**
* The full start time of the performance including date and time in string format.
*/
private String _startTimeString;
/**
* The start time of the performance in 24hr time in integer format.
*/
private int _startTime;
/**
* The end time of the performance.
*/
private int _endTime;
public Performance(Artist artist, String startTime, int duration) {
_artist = artist;
_startTimeString = startTime;
//Invokes the static method getStartTime to turn the String of date and time to just the time in integer format
_startTime = Time.getStartTime(startTime);
_duration = duration;
//Invoke static method getEndTime to get the end time of the performance
_endTime = Time.getEndTime(_startTimeString, _duration);
System.out.println("@Performance object created with artist " + artist.toString() + " at " + _startTimeString + " with duration " + _duration);
}
/**
* Return the artist for this performance.
* @return The {@link Artist} for this performance.
*/
public Artist getArtist() {
return _artist;
}
/**
* Return the start time for this performance.
* @return The start time for this performance.
*/
public int startTime() {
return _startTime;
}
/**
* Return the end time for this performance.
* @return The end time for this performance.
*/
public int endTime() {
return _endTime;
}
/**
* Return the duration for this performance.
* @return The duration for this performance.
*/
public int getDuration() {
return _duration;
}
public String startTimeString() {
return _startTimeString;
}
/**
* Determine whether this performance overlaps with the performance provided.
* Performance A overlaps with performance B if A's start time is before B's, but it
* finishes after B starts, or vice versa.
* @param existingPerformance The {@link Performance} to compare against.
* @return true if the two performances overlap otherwise false.
*/
public boolean overlaps(Performance existingPerformance) {
if((_startTime <= existingPerformance.startTime()) && (_endTime >= existingPerformance.startTime())) {
//Check if the dates are the same if the times overlap
if(Time.sameDate(existingPerformance.startTimeString(), _startTimeString) == true) {
return true;
}
}
else if ((existingPerformance.startTime() <= _startTime) && (existingPerformance.endTime() >= _startTime)) {
//Check if the dates are the same if the times overlap
if(Time.sameDate(existingPerformance.startTimeString(), _startTimeString) == true) {
return true;
}
}
return false;
}
@Override
public String toString() {
return _artist.toString() + ", " + _startTimeString + ", " + Integer.toString(_duration);
}
}