-
Notifications
You must be signed in to change notification settings - Fork 0
/
PokemonArrayList
213 lines (200 loc) · 7.22 KB
/
PokemonArrayList
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
import java.util.*;
/*
*ArrayList of Pokemon Objects A.4
*@author Nicholas Miyamoto-Pennywell
*@since 10/21/17
*/
public class PokeArrayListOfObjects{
static final int SIZE = 6;
public static void main(String[] args){
ArrayList<Pokemon> pokemonList= new ArrayList<>();//Pokemon ArrayLIST!!!! needs Change
Scanner userIn = new Scanner(System.in);
String inString = new String("");
boolean endLoop = false;
int count = 0;
/*Menu code Author @author Lisa Miller.
*menu code editor @editor Nicholas mp
*loops until stopping condition is given
*/
while(endLoop != true){//Menu
//menu text
System.out.println("Please enter the number of your choice:");
System.out.println("1. Add a Pokemon");
System.out.println("2. Print all Pokemon");
System.out.println("0. Exit the program");
System.out.print("What would you like to do? ");
//read in from user as a String -- much less errors can happen!
inString = userIn.nextLine();
//take off any spaces on the string
inString = inString.trim();
//just switch on the String no need to convert to int
switch(inString){
case "0": endLoop = true;
System.out.println("Good bye!");
break;
case "1": //do stuff to make a new Pokemon
System.out.println("\nMake your new Pokemon.\n");
System.out.println("Pokemon " + (count + 1) + ":");
if(pokemonList.size() == SIZE){//Array management replaces old Objects with new when limit reached.
pokemonList.remove(count);
}
pokemonList.add(count, PokeArrayListOfObjects.makePokemon());//Calls makePokemon Method);
count++;
System.out.println("\nPokemon Added\n");
//Array management restarts array when size reached
if(count == SIZE){
System.out.println(" |Pokemon List Full| ");
System.out.println("New Pokemon entries will replace old ones.");
count = 0;
}
break;
case "2": //print out all the Pokemon
System.out.println("\n****Printing user created Pokemon.****\n");
PokeArrayListOfObjects.printArray(pokemonList);//Calls printArray
break;
default: //not a valid menu entry
System.out.println("\n****Invalid menu choice.****\nPlease enter a 0, 1, or 2\n");
break;
}
}//Menu
}//Main
/*makePokemon Method
*Main calls method
*Method asks to make pokemon object then retruns it to Main.
*/
public static Pokemon makePokemon(){
String q1 = "What is the Pokemon's species?";
String c1 = "Choose the Pokemon's Species by entering the number of the Pokemon:\n";
String q2 = "Does the Pokemon have a name? Y/N:";
String q3 = "What is the Pokemon's name?";
String pOptions = "Bulbasaur : 1 \nIvysaur : 2\nVenasuar : 3\nCharmander : 4\nCharmeleon : 5\nCharizard : 6\nSquirtle : 7\nWartortle : 8\nBlastoise : 9\n";
Scanner scan = new Scanner(System.in);
String userIn = "";
int userNum = 0;
String uName = "";
boolean done = false;
boolean bName = false;
Pokemon p = null;
//Asking Pokemon Species
System.out.println(q1);
System.out.println(pOptions);
System.out.println(c1);
//Scanning User response, Checking results.
//While loop until correct set of numbers is chosen.
while(!done){
userIn = scan.nextLine();
try{
userNum = Integer.parseInt(userIn);
if(userNum > 9){//Checks for numbers out of bounds (1-9)
System.out.println("Pokemon selected not in data base. Please try Again... \n");
}else{
done = true;
}
}catch(NumberFormatException nfe){//EXCEPTIONS, if string is used instead of numbers
System.out.println("Please try again");
}
}
//Asking for Pokemon's Name.
done = false;
while(!done){//Loops for user input until either user inputs a name or says no.
System.out.println(q2);
try{
userIn = scan.nextLine();
switch(userIn){
case "Y":
case "y":
System.out.println(q3);
uName = scan.nextLine();
if(uName.isEmpty()){
done = false;
}else{
bName = true;
done = true;
}
break;
case "N":
case "n":
done = true;
break;
default:
System.out.println("Invalid input");
}
}catch(InputMismatchException ime){
System.out.println("Please try again.");
}
}//While loop for Name
if(bName != true){//if else statement to check for Name input
switch(userNum){//switch statement for Pokemon Object without Name
case 1:
p = new Bulbasaur();
break;
case 2:
p = new Ivysaur();
break;
case 3:
p = new Venusaur();
break;
case 4:
p = new Charmander();
break;
case 5:
p = new Charmeleon();
break;
case 6:
p = new Charizard();
break;
case 7:
p = new Squirtle();
break;
case 8:
p = new Wartortle();
break;
case 9:
p = new Blastoise ();
break;
default:
}
}else{
switch(userNum){//Switch statement for Pokemon Object with Name
case 1:
p = new Bulbasaur(uName);
break;
case 2:
p = new Ivysaur(uName);
break;
case 3:
p = new Venusaur(uName);
break;
case 4:
p = new Charmander(uName);
break;
case 5:
p = new Charmeleon(uName);
break;
case 6:
p = new Charizard(uName);
break;
case 7:
p = new Squirtle(uName);
break;
case 8:
p = new Wartortle(uName);
break;
case 9:
p = new Blastoise (uName);
break;
default:
}
}
return p;
}//makePokemon Method
/*printArray method
*Prints the objgects stored in the Array List in order
*/
public static void printArray(ArrayList <Pokemon> displayArrayList){
for(int l = 0; l < displayArrayList.size(); l++){
System.out.println("Pokemon " + (l+1) + ": \n" + displayArrayList.get(l));
//Array prints all 6 pokemon objects
}
}//printArray Method
}//Class