-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObjArray.java
347 lines (315 loc) · 9.11 KB
/
ObjArray.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
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
import java.util.Scanner;
/* Jackson & Norina
*/
public class ObjArray{
protected final int MAX;
protected static Object [] array;
protected int index; // (next empty slot)
protected int pointer;
protected int length;
//default constructor, instantiates array to MAX size and assigns 0 to index
public ObjArray() {
MAX = 75;
length = 0;
index = 0;
array = new Object[MAX];
pointer = 0;
}
//nondefault constructor to instantiate an array to size, assigns 0 to index
public ObjArray(int size) {
MAX = 75;
length = size;
index = 0;
pointer = 0;
array = new Object[size];
}
//nondefault constructor that will assign a new array and new value to index
public ObjArray(Object [] anArr, int newIndex) {
MAX = 75;
array = anArr;
index = newIndex;
}
public int getLength() {
return array.length;
}
//return a copy of the array, accessor
public Object[] getobjArr () {
return array;
}
//assign a new array, mutator
public void setobjArr(Object[] anObjArr) {
array = anObjArr;
}
//return # of actual data in array, accessor
public int getIndex() {
return index;
}
//return current position
public int getPointer() {
return pointer;
}
//returns deep copy of the object array
public Object[] getArray() {
Object [] deepArr = new Object[index];
int i;
for (i = 0; i < index; i++) {
deepArr[i] = array[i];
}
return deepArr;
}
//assign a new index, mutator
public void setIndex(int anIndex) {
index = anIndex;
}
public void setPointer (int sPoint) {
pointer = sPoint;
}
//return an object at given pos
public Object getObject(int pos) {
return array[pos];
}
//return the string with contents of array
public String toString() {
String toStrng = " ";
int i;
for (i = 0; i <= index-1; i++) {
toStrng = toStrng + array[i].toString();
}
return toStrng;
}
//insert a new string into the next empty slot of the array if there is room, inc index
public void add(Object anObj) {
if (index < 50) {
array[index] = anObj;
index++;
}
}
//searches the list for an object and returns the index where that object
//has been found or -1 if not found
public int isThere(Object anObj) {
int exist = -1;
int i;
for (i = 0; i < index; i++) {
if (array[i].equals(anObj) == true) {
exist = i;
}
}
return exist;
}
//insert an object at particular index moving everything down
public void insertObject(Object anObj, int pos) {
int i;
for (i = index; i >= pos; i--) {
if (i > 0) {
array[i] = array[i-1];
}
}
array[pos] = anObj;
}
//replace an object with another object
public void setObject(Object anObj, int pos) {
array[pos] = anObj;
}
//delete object from the specified position, check if list is empty
public void delete (int delIndex) {
if (index > 1) {
int i;
for (i = delIndex; i <= index-1; i++) {
array[i] = array[i+1];
}
index--;
}
else if (index == 0) {
System.out.println("List is empty");
}
}
//is it full
public boolean isFull() {
boolean check = false;
if (index+1 == MAX) {
check = true;
}
else {
check = false;
}
return check;
}
//is it empty
public boolean isEmpty() {
boolean check = false;
if (index == 0) {
check = true;
}
else {
check = false;
}
return check;
}
//clears the entire array
public void clear() {
int i;
for (i = 0; i < index; i++) {
array[i] = null;
}
index = 0;
}
//decreases the array size by one
public void trim() {
Object [] trimmedArr = new Object[index--];
int i;
for (i = 0; i < index; i++) {
trimmedArr[i] = array[i];
}
array = trimmedArr;
}
//doubles the size of the array
public void moreCapacity () {
if (index == MAX) {
int newsize = index * 2;
int i;
Object [] moar = new Object [newsize];
for (i = 0; i < index; i++) {
moar[i] = array[i];
}
array = moar;
}
else {
System.out.println("Cannot expand array because current array has not reached maximum size");
}
}
// resets the pointer
public void reset () {
pointer = 0;
}
public boolean hasNext() {
boolean check = true;
if (pointer < index-1) {
check = true;
}
else {
check = false;
}
return check;
}
public Object getNext() {
pointer++;
return array[pointer-1];
}
//swaps objects in the desired indexes
public void swap(int in1, int in2) {
Object temp = new Object();
temp = array[in1];
array[in1] = array[in2];
array[in2] = temp;
}
//adds a player (used to be in application class but it looked ugly)
public void addPlayer(SearchNSort player) {
Scanner mScan = new Scanner(System.in);
String nRole;
String nName;
double nKd;
String garb;
int nWinnings;
double nRating;
double nAdr;
JJNB_Team nTeam = new JJNB_Team();
JJNB_Rifler nRifler;
JJNB_Awper nAwper;
JJNB_InGameLeader nIGL;
System.out.print("Enter the new player's role: ");
nRole = mScan.next().toLowerCase();
index++;
//makes sure to check every variable of a rifler
if (nRole.equals("rifler")) {
System.out.print("What is the new player's name: ");
if (mScan.hasNext()) {
nName = mScan.next();
garb = mScan.nextLine();
System.out.print("What is the new player's k/d: ");
if (mScan.hasNextDouble()) {
nKd = mScan.nextDouble();
garb = mScan.nextLine();
System.out.print("What is the new player's winnings: ");
if (mScan.hasNextInt()) {
nWinnings = mScan.nextInt();
garb = mScan.nextLine();
System.out.print("What is the new player's rating: ");
if (mScan.hasNextDouble()) {
nRating = mScan.nextDouble();
garb = mScan.nextLine();
System.out.print("What is the new player's ADR: ");
if (mScan.hasNextDouble()) {
nAdr = mScan.nextDouble();
nRifler = new JJNB_Rifler(nName, nKd, nWinnings, nRating, nAdr, nTeam);
player.add(nRifler);
System.out.println("Player added: " + nRifler.toString());
}
}
}
}
}
}
//makes sure to check every variable of an awper
if (nRole.equals("awper")) {
System.out.print("What is the new player's name: ");
if (mScan.hasNext()) {
nName = mScan.next();
garb = mScan.nextLine();
System.out.print("What is the new player's k/d: ");
if (mScan.hasNextDouble()) {
nKd = mScan.nextDouble();
garb = mScan.nextLine();
System.out.print("What is the new player's winnings: ");
if (mScan.hasNextInt()) {
nWinnings = mScan.nextInt();
garb = mScan.nextLine();
System.out.print("What is the new player's rating: ");
if (mScan.hasNextDouble()) {
nRating = mScan.nextDouble();
garb = mScan.nextLine();
System.out.print("What is the new player's Opening pick percentage: ");
if (mScan.hasNextDouble()) {
nAdr = mScan.nextDouble();
garb = mScan.nextLine();
nAwper = new JJNB_Awper(nName, nKd, nWinnings, nRating, nAdr, nTeam);
player.add(nAwper);
System.out.println("Player added: " + nAwper.toString());
}
}
}
}
}
}
//makes sure to check every variable of an in game leader
if (nRole.equals("ingameleader")) {
System.out.print("What is the new player's name: ");
if (mScan.hasNext()) {
nName = mScan.next();
garb = mScan.nextLine();
System.out.print("What is the new player's k/d: ");
if (mScan.hasNextDouble()) {
nKd = mScan.nextDouble();
garb = mScan.nextLine();
System.out.print("What is the new player's winnings: ");
if (mScan.hasNextInt()) {
nWinnings = mScan.nextInt();
garb = mScan.nextLine();
System.out.print("What is the new player's rating: ");
if (mScan.hasNextDouble()) {
nRating = mScan.nextDouble();
garb = mScan.nextLine();
System.out.print("What is the new player's clutch percentage: ");
if (mScan.hasNextDouble()) {
nAdr = mScan.nextDouble();
garb = mScan.nextLine();
nIGL = new JJNB_InGameLeader(nName, nKd, nWinnings, nRating, nAdr, nTeam);
player.add(nIGL);
System.out.println("Player added: " + nIGL.toString());
}
}
}
}
}
}
}
}