-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathBandGigManager.java
More file actions
211 lines (167 loc) · 5.79 KB
/
BandGigManager.java
File metadata and controls
211 lines (167 loc) · 5.79 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
package org.codedifferently;
import java.util.ArrayList;
import java.util.Collections;
//stores main abstraction of modifier methods we call when we want to update/view/adjust fields in the program
public class BandGigManager {
//arraylists used because we need a collection to store objects that is not fixed in size
//needed to be able to easily add and remove objects from list, and access them with indexing
//for this reason ArrayList was a good choice
private final ArrayList<Gig> gigs;
private final ArrayList<String> songCatalog;
private final ArrayList<String> defaultBandMembers;
//constructor, no paramaters needed
public BandGigManager() {
gigs = new ArrayList<>();
songCatalog = new ArrayList<>();
defaultBandMembers = new ArrayList<>();
defaultBandMembers.add("Alex");
defaultBandMembers.add("Jonny");
defaultBandMembers.add("Bailey");
defaultBandMembers.add("Matty");
}
//add gig to ArrayList
public void addGig(Gig gig) {
gigs.add(gig);
}
//getter to return list of gigs
public ArrayList<Gig> getGigs() {
return gigs;
}
//find gig at index in ArrayList
public Gig findGigByIndex(int index) {
if (index >= 0 && index < gigs.size()) {
return gigs.get(index);
}
return null;
}
//update gig complete boolean
public boolean markGigCompleteByIndex(int index) {
Gig gig = findGigByIndex(index);
if (gig == null) {
return false;
}
gig.markCompleted();
return true;
}
//display all gigs in array list
public void viewAllGigs() {
if (gigs.isEmpty()) {
System.out.println("No gigs available.");
return;
}
//for loops are going to allow us to iterate through the list
for (int i = 0; i < gigs.size(); i++) {
System.out.println((i + 1) + ". " + gigs.get(i));
System.out.println();
}
}
//display all gigs that aren't completed
public void viewUpcomingGigs() {
boolean found = false;
for (int i = 0; i < gigs.size(); i++) {
if (!gigs.get(i).isCompleted()) {
System.out.println((i + 1) + ". " + gigs.get(i));
System.out.println();
found = true;
}
}
if (!found) {
System.out.println("No upcoming gigs.");
}
}
//display all gigs that are completed
public void viewCompletedGigs() {
boolean found = false;
for (int i = 0; i < gigs.size(); i++) {
if (gigs.get(i).isCompleted()) {
System.out.println((i + 1) + ". " + gigs.get(i));
System.out.println();
found = true;
}
}
if (!found) {
System.out.println("No completed gigs.");
}
}
//sum payments of the gigs
public double calculateTotalEarnings() {
double total = 0.0;
//enhanced for loop to iterate through list, only add to sum if gig is completed
for (Gig gig : gigs) {
if (gig.isCompleted()) {
total += gig.getPayment();
}
}
return total;
}
//add song to catalog list
public void addSongToCatalog(String song) {
songCatalog.add(song);
}
//get entire song catalog list object
public ArrayList<String> getSongCatalog() {
return songCatalog;
}
//not used
public void addDefaultBandMember(String member) {
defaultBandMembers.add(member);
}
//not used, getter
public ArrayList<String> getDefaultBandMembers() {
return defaultBandMembers;
}
//clear lineup and add members in defaultBandMembers to gig lineup
public void applyDefaultLineup(Gig gig) {
gig.getLineup().clear();
gig.getLineup().addAll(defaultBandMembers);
}
public void generateSetlistForGig(Gig gig, int numberOfSongs) {
if (songCatalog.isEmpty()) {
return;
}
ArrayList<String> tempSongs = new ArrayList<>(songCatalog);
//randomly reorder elements in collection tempSongs
Collections.shuffle(tempSongs);
gig.clearSetlist();
for (int i = 0; i < numberOfSongs && i < tempSongs.size(); i++) {
gig.addSong(tempSongs.get(i));
}
}
//takes gig index to add generated setlist to specific gig
public boolean generateSetlistForGigByIndex(int index, int numberOfSongs) {
Gig gig = findGigByIndex(index);
if (gig == null || gig.isCompleted() || songCatalog.isEmpty()) {
return false;
}
generateSetlistForGig(gig, numberOfSongs);
return true;
}
//add song to setlist array list, if/else locks out gig if completed
public boolean addSongToGigSetlist(int gigIndex, String song) {
Gig gig = findGigByIndex(gigIndex);
if (gig == null || gig.isCompleted()) {
return false;
}
gig.addSong(song);
return true;
}
//remove song from setlist array list in gig, if/else locks out gig if completed
public String removeSongFromGigSetlist(int gigIndex, int songIndex) {
Gig gig = findGigByIndex(gigIndex);
if (gig == null || gig.isCompleted()) {
return null;
}
return gig.removeSongAtIndex(songIndex);
}
//display gig info, lineup and setlist for a gig
public void viewGigDetails(int index) {
Gig gig = findGigByIndex(index);
if (gig == null) {
System.out.println("Invalid gig selection.");
return;
}
System.out.println(gig);
System.out.println("Lineup: " + gig.getLineup());
System.out.println("Setlist: " + gig.getSetlist());
}
}