-
Notifications
You must be signed in to change notification settings - Fork 0
/
Theatre.java
113 lines (98 loc) · 3.11 KB
/
Theatre.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;
/**
* Imported to be able to use ArrayLists as this makes it much easier to add elements than arrays
*/
import java.util.ArrayList;
public class Theatre {
/**
* Creates a theatre object that will register artists and schedule performances
* This object will also hold the arrays of performances and artists and can also
* display the current state of the theatre.
*/
/**
* List of performances
*/
private ArrayList<Performance> _performances = new ArrayList<Performance>();
/**
* List of reference types to Artist objects
*/
private ArrayList<Artist> _artistList = new ArrayList<Artist>();
/**
* List of the Artist objects' names
*/
private ArrayList<String> _artistNames = new ArrayList<String>();
public Theatre() {
}
/**
* Displays the current status of the theatre (registered artists
* and scheduled performances).
*/
public void display() {
//If no artists have been registered.
if(_artistList.isEmpty()) {
System.out.println("No artists registered.");
}
else {
System.out.println("Registered artists: ");
for(int i = 0; i < _artistList.size(); i++) {
System.out.println("\t" + _artistList.get(i).toString());
}
}
//If no performances have been scheduled.
if(_performances.isEmpty()) {
System.out.println("No performances scheduled.");
}
else {
System.out.println("Scheduled performances: ");
for(int i = 0; i < _performances.size(); i++) {
System.out.println("\t" + _performances.get(i).toString());
}
}
}
/**
* Registers an artist with the theatre.
* @param artist The artist to register
*/
public void registerArtist(Artist artist) {
//If the artist has already been registered, will display error message.
if(_artistNames.contains(artist.toString()) == true) {
System.out.println(artist.toString() + " has already been registered.");
}
else {
_artistNames.add(artist.toString());
_artistList.add(artist);
}
}
/**
* Schedules the performance for the performance object
* @param thisPerformance The performance object to schedule
*/
public void schedulePerformance(Performance thisPerformance) {
//If the artist has not been registered to the theatre.
if(_artistNames.contains(thisPerformance.getArtist().toString()) == false) {
System.out.println("Artist has not been registered.");
}
else {
//Check if performance ends at or after midnight
if(thisPerformance.endTime() < 2360) {
int counter = 0;
//Check for performance time overlap
for(int i = 0; i < _performances.size(); i++) {
if(_performances.get(i).overlaps(thisPerformance)) {
counter++;
}
}
//Only when no overlap was found, will it add to the _performance list.
if(counter == 0) {
_performances.add(thisPerformance);
}
else {
System.out.println("Invalid performance time. Performances may not be overlap nor go past midnight.");
}
}
else {
System.out.println("Invalid performance time. Performances may not be overlap nor go past midnight.");
}
}
}
}