-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayMenu.java
More file actions
43 lines (40 loc) · 1.21 KB
/
ArrayMenu.java
File metadata and controls
43 lines (40 loc) · 1.21 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
import java.util.Scanner;
public class ArrayMenu {
static Scanner scn = new Scanner(System.in);
static ArrayStore array;
public static void main(String args[]){
String[] methods = {"Create","Insert","Delete","Print","Exit"};
Menu menu = new Menu(methods);
boolean exit = false;
int choices = 0;
do{
System.out.println(menu.displayMenu());
System.out.println("Enter your choice:");
int choice = scn.nextInt();
switch(choice){
case 1: System.out.println("Enter array size:");
int size = scn.nextInt();
array = new ArrayStore(size);
System.out.println("ArrayCreated");
break;
case 2: System.out.println("enter number to be inserted:");
int number = scn.nextInt();
boolean inserted = array.insert(number);
if(inserted) System.out.println("Insertion Succesful");
else System.out.println("Insertion Failed");
break;
case 3: break;
case 4: break;
case 5: exit = true;
default: if(choices >= 3){
exit = true;
System.out.println("Sorry! Exiting");
System.out.flush();
}else{
choices++;
System.out.println("Choose Carefully." + (4-choices) +" choices left!");
}
}
}while(!exit);
}
}