-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.java
More file actions
409 lines (368 loc) · 10.1 KB
/
test.java
File metadata and controls
409 lines (368 loc) · 10.1 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
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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
import java.util.Scanner;
/**
* the test class contains menu's
* and allows users to munipulate 3 different digitTrees
* <br><br>
* @author Allen McDermott
* @since 11/16/14
*/
public class test {
/**public static void main(String[] args) {
Scanner key = new Scanner(System.in);
DigitTree tree = new DigitTree();
DigitTree tri = new DigitTree();
DigitTree troo = new DigitTree();
int j = 1;
int k =1;
men1up(tree,tri,troo);
}**/
/**
* Tree,tri,troo are all DigitTrees that can be used with other methods
**/
DigitTree tree;
DigitTree tri;
DigitTree troo;
/** test is a constructor for test it creates 3 new digitTrees
**/
public test() {
tree = new DigitTree();
tri = new DigitTree();
troo = new DigitTree();
}
//start calls method men1up
public void start() {
men1up();
}
//menu1 displays a menu
public static void menu1() {
System.out.println();
System.out.println("Please select an option: ");
System.out.println("[1]DigitTree #1");
System.out.println("[2]DigitTree #2");
System.out.println("[3]DigitTree #3");
System.out.println("[4]help");
System.out.println("[5]exit");
System.out.println();
}
//men1up displays menu1 and asks input from the user that will
// call another method depending on the inpu
public void men1up() {
Scanner key = new Scanner(System.in);
int k = 1;
String j;
while(k>0) {
menu1();
j = key.nextLine();
if(j.equals("1")) {
men2up(1);
k=1;
}
else if(j.equals("2")) {
men2up(2);
k=2;
}
else if(j.equals("3")) {
men3up();
k=3;
}
else if(j.equals("4")){
help();
k=4;
}
else if(j.equals("5")){
k=-1;
System.out.println("Have a nice day! :)");
}
else {
System.out.println("That is not an option (make sure caps are turned off)");
}
}
}
//menu2 displays a menu
//@param k is the digit tree the user is in
public static void menu2(int k) {
System.out.println();
System.out.println("You are in digitTree #"+k);
System.out.println("Select a command:");
System.out.println("[1]add");
System.out.println("[2]contains");
System.out.println("[3]delete");
System.out.println("[4]size");
System.out.println("[5]nodeCount");
System.out.println("[6]toString");
System.out.println("[7]union");
System.out.println("[8]intersect");
System.out.println("[9]subtract");
System.out.println("[10]clear");
System.out.println("[11]Iterate");
System.out.println("[12]DigitTree #3");
System.out.println("[13]back");
System.out.println();
}
//men2up displays menu2 and asks the user for input which
//will be used to call different methods
public void men2up(int i) {
Scanner key = new Scanner(System.in);
int k=1;
String j;
if(i==1) {
while(k>0) {
menu2(i);
j = key.nextLine();
if(j.equals("1")) {
try {
addMethod(tree);
}
catch(DigitFormatException e)
{
System.out.println(e.getMessage());
}
}
else if(j.equals("2")) {
containsMethod(tree);
}
else if(j.equals("3")) {
deleteMethod(tree);
}
else if(j.equals("4")) {
sizeMethod(tree);
}
else if(j.equals("5")) {
nodeCountMethod(tree);
}
else if(j.equals("6")) {
toStringMethod(tree);
}
else if(j.equals("7")) {
unionMethod(tree,tri);
}
else if(j.equals("8")) {
intersectMethod(tree,tri);
}
else if(j.equals("9")) {
subtractMethod(tree,tri,1,2);
}
else if(j.equals("10")) {
clearMethod(tree,1);
}
else if(j.equals("11")) {
iteratorMethod(tree);
}
else if(j.equals("12")) {
men3up();
}
else if(j.equals("13")) {
k=-1;
}
else {
System.out.println("That is not a valid command (make sure caps lock is off)");
}
}
}
else if(i==2) {
while(k>0) {
menu2(i);
j = key.nextLine();
if(j.equals("1")) {
try {
addMethod(tri);
}
catch(DigitFormatException e)
{
System.out.println(e.getMessage());
}
}
else if(j.equals("2")) {
containsMethod(tri);
}
else if(j.equals("3")) {
deleteMethod(tri);
}
else if(j.equals("4")) {
sizeMethod(tri);
}
else if(j.equals("5")) {
nodeCountMethod(tri);
}
else if(j.equals("6")) {
toStringMethod(tri);
}
else if(j.equals("7")) {
unionMethod(tri,tree);
}
else if(j.equals("8")) {
intersectMethod(tri,tree);
}
else if(j.equals("9")) {
subtractMethod(tri,tree,2,1);
}
else if(j.equals("10")) {
clearMethod(tri,2);
}
else if(j.equals("11")) {
iteratorMethod(tri);
}
else if(j.equals("12")) {
men3up();
}
else if(j.equals("13")) {
k=-1;
}
else {
System.out.println("That is not a valid command (make sure caps lock is off)");
}
}
}
}
//addMethod adds an item to either tree or tri depending on the param
//throws DigitFormatException if the user inputs a non numeric value
public static void addMethod(DigitTree t) throws DigitFormatException {
Scanner key = new Scanner(System.in);
String s;
System.out.println("Input digit String to be added:");
s = key.nextLine();
int iwaq;
for(int i = 0; i<s.length();i++) {
iwaq=0;
while(iwaq <10) {
if(s.charAt(i)==Character.forDigit(iwaq,10)) {
iwaq=11;
}
iwaq++;
}
if(iwaq-1<10) {
System.out.println(s.charAt(i)+"REEE");
throw new DigitFormatException();
}
}
System.out.println(s+" was added to DigitTree "+t.add(s));
}
//deleteMethod deletes an item from tree or tri depending on the param
// @param t is a digitTree that an item will be deleted from
public static void deleteMethod(DigitTree t) {
Scanner key = new Scanner(System.in);
String s;
System.out.println("Input digit String to be deleted:");
s = key.nextLine();
try {
System.out.println(s+" was deleted from DigitTree "+t.delete(s));
}
catch(DigitFormatException e){System.out.println("false");}
}
//contains method searches threw a tree to see if it contains a value
//@param tree that will be searched threw
public static void containsMethod(DigitTree t) {
Scanner key = new Scanner(System.in);
String s;
System.out.println("Input digit String to see if its contained in tree:");
s = key.nextLine();
try {
System.out.println("DigitTree contains "+s+" "+t.contains(s));
}
catch(DigitFormatException e) { System.out.println("false");
}
}
//sizeMethod returns the size of a digitTree
//@param t is the digit tree that we will get the size from
public static void sizeMethod(DigitTree t) {
System.out.println("The size of your DigitTree is "+t.size());
}
//nodeCount returns the amount of nodes in a digit Tree
//@param digit tree to find amount of nodes from
public static void nodeCountMethod(DigitTree t) {
System.out.println("The node count for this DigitTree is "+t.nodeCount());
}
//toStringMethod makes a digitree to a string
//@param digitTree to make into a string
public static void toStringMethod(DigitTree t) {
System.out.println(t.toString());
}
//unionMethod makes the union of to digitTrees
//@param t digitTree to make into a union
//@param ot DigitTree to make into a union
public void unionMethod(DigitTree t, DigitTree ot) {
troo = t.union(ot);
System.out.println("DigitTree #3 is now the union of DigitTrees #1, and #2");
}
//intersect intersects two digitTrees
//@param digitTree to intersect
//@param digitTree to inteersect
public void intersectMethod(DigitTree t, DigitTree ot) {
troo = t.intersect(ot);
System.out.println("DigitTree #3 is now the intersect of DigitTree #1, and #2");
}
//subtractMethod subtracts one tree from another
//@param digitTree to be subtracted by
//@param digit tree thta will be doing the subtracting
//@param int toor # declaring what tree it is
//@param taar # declaring what tree it is
public void subtractMethod(DigitTree t, DigitTree ot,int toor, int taar) {
troo = t.subtract(ot);
System.out.println("DigitTree #3 is now DigitTree #"+toor+" subtracted by DigitTree #"+taar);
}
//clearMethod clears a digitTree
//@param digitTree to clear
public void clearMethod(DigitTree t,int itts) {
t.clear();
System.out.println("Digit tree #"+itts+" was cleared");
}
public void iteratorMethod(DigitTree t) {
t.iterator();
}
// menu3 displays a menu
public static void menu3() {
System.out.println();
System.out.println("You are in digitTree #3!");
System.out.println("Select a command;");
System.out.println("[1]contains");
System.out.println("[2]size");
System.out.println("[3]nodeCount");
System.out.println("[4]toString");
System.out.println("[5]clear");
System.out.println("[6]Iterate");
System.out.println("[7]back");
System.out.println();
}
//men3up displays menu3 and asks user for input
public void men3up() {
Scanner key = new Scanner(System.in);
int k=1;
String j;
while(k>0) {
menu3();
j = key.nextLine();
if(j.equals("1")) {
containsMethod(troo);
}
else if(j.equals("2")) {
sizeMethod(troo);
}
else if(j.equals("3")) {
nodeCountMethod(troo);
}
else if(j.equals("4")) {
toStringMethod(troo);
}
else if(j.equals("5")) {
clearMethod(troo,3);
}
else if(j.equals("6")) {
iteratorMethod(troo);
}
else if(j.equals("7")) {
k=-1;
}
else {
System.out.println("That is not a command (make sure that caps lock is off)");
}
}
}
//help deisplays a message for the interactions of digit tree #3
public static void help() {
System.out.println("For digitTree #3 you can only look at it (you can't directly add,delete,ect), it represents the last method you called from union, intersect, and delete in either tree #1 or tree #2. Therefor you can only create it by going in to DigitTree #1 or #2, and using the union, intersect, and subtract methods which will then use tree #2 (if you are currently in tree #1), or tree #1 (if you are currently in tree #2) to create tree #3 which may change depend on the last time you have used those three methonds.");
System.out.println("Press any key to go back:");
System.out.println();
Scanner key = new Scanner(System.in);
key.nextLine();
}
}