-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompLab3.java
174 lines (129 loc) · 5.98 KB
/
compLab3.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
import java.io.File;
import java.util.Scanner;
public class compLab3 {
public static void main(String[] args) throws Exception{
// reading the file to convert it into an array
File file = new File("/Users/rubenarciba/Desktop/pokemonList.txt");
Scanner scan = new Scanner(file);
int counter = 0;
while(scan.hasNextLine()){
counter++;
scan.nextLine();
}
String pokemonBox[][] = new String[counter][13];
scan = new Scanner(file);
int index = 0;
while(scan.hasNextLine()){
String line = scan.nextLine();
pokemonBox[index] = line.split(",");
index++;
}
// nodes of pokemons
LLNode head = new LLNode(pokemonBox[1]);
LL pkmnParty = new LL(head);
boolean exit = false;
while(exit == false){
// manu of the game
Scanner input2 = new Scanner(System.in);
System.out.println("-------------------------------");
System.out.println("Welcome to the Pokemon Center\n" +
"Pleace select on of the forllowing options\n" +
"1) View Box\n" +
"2) View Party \n" +
"3) Deposit Pokemon (add to party)\n" +
"4) Withdraw Pokemon (remove from party)\n" +
"5) View Pokemon Stats\n" +
"6) Log Out");
int option = input2.nextInt();
//done
// option 1 of the menu
if(option == 1){
Scanner input = new Scanner(System.in);
System.out.println("Chose a filter criteria (only one), or type anything else to see everyone in the box \n"+
"-Level\n" +
"-Generation");
String filter = input.next();
displayPokemon(pokemonBox, filter);
}
else if(option == 2){
pkmnParty.displayParty(pkmnParty.head);
}
else if(option == 3){
Scanner input = new Scanner(System.in);
System.out.println("Enter name of the pokemon you whant to add: ");
String pokemon = input.next();
LLNode pkmn = null;
if(pkmnParty.inParty(pokemon)==false){
for(int row = 1; row<pokemonBox.length; row++){
if(pokemonBox[row][1].equals(pokemon)){
pkmn = new LLNode(pokemonBox[row]);
}
}
}
pkmnParty.addToParty(pkmn);
}
else if(option == 4){
Scanner input = new Scanner(System.in);
System.out.println("Enter name of the pokemon you whant to remove from party: ");
String pokemon = input.next();
pkmnParty.inParty(pokemon);
pkmnParty.removeFromParty(pokemon);
}
else if(option ==5 ){
Scanner input = new Scanner(System.in);
System.out.println("Enter the pokemon you whant to view: ");
String toView = input.next();
for(int row = 1; row<pokemonBox.length; row++){
if(pokemonBox[row][1].equals(toView)){
for(int colum = 1; colum<pokemonBox[row].length; colum++){
System.out.print(pokemonBox[row][colum] + " ");
}
System.out.println();
}
}
}
else if(option == 6){
System.out.println("Ending program....");
System.exit(0);
}
}
}
/**
* This method displays all the Pokemon, given the type of filter, if no valid filter is given, display all Pokemon
*
* @param pokemonBox
* @param filter
* @return void
*/
public static void displayPokemon(String[][] pokemonBox, String filter){
Scanner input = new Scanner(System.in);
if(filter.equals("Level")){
System.out.println("Enter lower bound level you whant to filter by (min 1, max 100): ");
int lower = input.nextInt();
System.out.println("Enter upper bound level you whant to filter by (min 1, max 100): ");
int upper = input.nextInt();
for(int row = 1; row<pokemonBox.length; row++){
if(Integer.parseInt(pokemonBox[row][4])>=lower && Integer.parseInt(pokemonBox[row][4])<=upper){
System.out.println(pokemonBox[row][0] + ") " + pokemonBox[row][1] + " Level: " + pokemonBox[row][4]);
}
}
}
else if (filter.equals("Generation")){
System.out.println("pleace enter the generation by which you what to filter by (Only gens 1, 2, and 3 are available): ");
int gen = input.nextInt();
for(int row = 1; row < pokemonBox.length; row++){
if(Integer.parseInt(pokemonBox[row][12]) == gen){
System.out.println(pokemonBox[row][0] + ") " + pokemonBox[row][1] + " Gen: " + pokemonBox[row][12]);
}
}
}
else{
for(int row = 1; row < pokemonBox.length; row++){
for(int colum = 0; colum<pokemonBox[row].length; colum++){
System.out.print(pokemonBox[row][colum] + " ");
}
System.out.println();
}
}
}
}