-
Notifications
You must be signed in to change notification settings - Fork 0
/
FishingDriver.java
159 lines (138 loc) · 4.97 KB
/
FishingDriver.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
import java.util.ArrayList;
import java.util.Random;
/**
* Driver for Fishable I_a testing.
* @author Lisa Miller
* @since 4/24/22
*/
public class FishingDriver {
/** Maximum pond capacity for random hooking. */
static final int POND_CAPACITY = 40;
/** main method.
* @param args not used.
*/
public static void main(String[] args) {
//ArrayList to simulate a fishpond/lokoi'a
ArrayList<FishableI_a> lokoi_a = new ArrayList<>();
boolean debug = true; //for printing
lokoi_a = FishingDriver.fillPond();
if (debug) {
System.out.println(lokoi_a);
}
//Let fish in pond grow some
//eat and grow for 24 months
FishingDriver.growFish(lokoi_a);
//now lets open the pond for fishing!
FishingDriver.lawai_a(lokoi_a);
} //close main
/**
* Adds 40 baby I_a to ArrayList.
* This should match POND_CAPACITY.
* @return ArrayList with small I_a in it.
*/
public static ArrayList<FishableI_a> fillPond() {
ArrayList<FishableI_a> al = new ArrayList<>();
//make 40 fish in the pond
//10 of baby of each species
for (int i = 0; i < 10; i++) {
al.add(new MoiLi_i());
}
for (int i = 0; i < 10; i++) {
al.add(new Oama());
}
for (int i = 0; i < 10; i++) {
al.add(new Pua_ama());
}
for (int i = 0; i < 10; i++) {
al.add(new Ohua());
}
//for testing empty locations
// for (int i = 0; i < 30; i++) {
// al.remove(i);
// }
return al;
} //fillPond method
/**
* Runs arraylist of I_a through 24 eating/growing cycles.
* @param al the list of fish.
*/
public static void growFish(ArrayList<FishableI_a> al) {
FishableI_a ia;
boolean debug = false; //turn printing on and off
for (int m = 0; m < 24; m++) {
//all fish in the pond
for (int i = 0; i < al.size(); i++) {
//loop over array
if (debug) {
System.out.println("==========================");
System.out.println("Feeding the fish" + i);
System.out.println("==========================\n");
}
ia = al.get(i);
if (debug) {
System.out.println(ia);
}
try { //must check for need to levelUp
//use EnglishName because doesn't change with size
if (ia.getEnglishName().equals("Striped Mullet")) {
ia.eat("algae");
} else if (ia.getEnglishName().equals("Goatfish")
|| ia.getEnglishName().equals("Yellowfin Goatfish")
|| ia.getEnglishName().equals("Square-spot Goatfish")) {
ia.eat("worms");
} else if (ia.getEnglishName().equals("Parrotfish")) {
ia.eat("algae");
} else if (ia.getEnglishName().equals("Six-fingered threadfin")) {
ia.eat("crustaceans");
}
if (debug) {
System.out.println("****After eat and grow: " + ia.getName()
+ ": " + ia.getLength() + "\n");
}
} catch (FishSizeException fe) {
//need to level up
ia = ia.levelUp();
if (debug) {
System.out.println(fe.getMessage());
System.out.println("**** After levelUp: " + ia + "\n");
}
}
al.set(i, ia);
}
} // close m loop
} //close growFish method
/**
* simulate fishing/lawai'a.
* @param fishPond arrayList of fish to be caught
*/
public static void lawai_a(ArrayList<FishableI_a> fishPond) {
Random randGen = new Random();
FishableI_a ia;
int chosenFish = 0;
boolean isCaught = false;
boolean isLegal = false;
chosenFish = randGen.nextInt(POND_CAPACITY);
try {
ia = fishPond.get(chosenFish);
System.out.println("You have hooked a fish!");
//randomly caught or not
isCaught = randGen.nextBoolean();
if (isCaught) {
System.out.println("You have caught a fish!");
System.out.println(ia);
System.out.println("You have kept your fish");
fishPond.remove(chosenFish); //take fish out of the pond
if (ia.isLegalSize()) {
System.out.println("Your fish is legal");
} else {
System.out.println("You kept an illegal fish!");
System.out.println("You got a ticket and all of your fish were confiscated!");
}
} else {
System.out.println("Your fish got away!");
}
} catch (IndexOutOfBoundsException ie) { //fish has been removed already
System.out.println("You didn't hook anything.");
}
} //close lawai_a method
}