-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli2.java
More file actions
151 lines (121 loc) · 4.57 KB
/
Copy pathcli2.java
File metadata and controls
151 lines (121 loc) · 4.57 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
import java.util.ArrayList;
import java.util.Scanner;
public class cli2 {
private static ArrayList<String> ticketNumbers = new ArrayList<>();
private static ArrayList<String> descriptions = new ArrayList<>();
private static ArrayList<String> porioritries = new ArrayList<>();
private static final String[] PRIORITY_OPTIONS = {"LOW", "MEDIUM","HIGH" };
private static final String ADMIN_PIN = "1234";
public static void main (String[] args ){
Scanner scanner = new Scanner(System.in);
boolean running = true ;
while (running ) {
System.out.println("Main Menu") ;
System.out.println("1.Customer operations") ;
System.out.println("2.Admin Operations") ;
System.out.println("3.Exit") ;
System.out.println("Choose an operation :") ;
int choice = scanner.nextInt();
scanner.nextLine();
if (choice == 1) {
customerOperations(scanner);
}else if (choice == 2){
adminOperations(scanner);
}else if (choice == 3){
System.out.println("Exiting the application.Goodbye !");
running = false;
}else{
System.out.println("Invalid option.Try again.");
}
}
scanner.close();
}
private static void customerOperations(Scanner scanner) {
boolean customermenu = true;
while (customermenu){
System.out.println(" Customer operations ");
System.out.println("1.create Ticket : ");
System.out.println("2.Back");
System.out.println("Choose an operation");
int choice = scanner.nextInt();
scanner.nextLine();
if (choice == 1) {
createTicket(scanner);
} else if (choice == 2) {
customermenu = false;
} else {
System.out.println("invalid option. try again");
}
}
}
private static void createTicket(Scanner scanner){
System.out.println("Enter Ticket num : ");
String ticketnum = scanner.nextLine();
System.out.print("Enter description : ");
String description = scanner.nextLine();
System.out.println("select priority: ");
for (int i = 0; i < PRIORITY_OPTIONS.length; i++){
System.out.println((i + 1) + " . " + PRIORITY_OPTIONS[i]);
}
int prioritychoice = scanner.nextInt();
scanner.nextLine();
if (prioritychoice < 1 || prioritychoice > PRIORITY_OPTIONS.length){
System.out.println("invalid priority selection. Ticket not created.");
return;
}
String prioritry = PRIORITY_OPTIONS[prioritychoice - 1];
ticketNumbers.add(ticketnum);
descriptions.add(description);
porioritries.add(prioritry);
System.out.println(("Ticket created successfully! "));
}
private static void adminOperations(Scanner scanner){
System.out.println("Enter Admin PIN: ");
String pin = scanner.nextLine();
if (!pin.equals(ADMIN_PIN)){
System.out.println("invalid pin. access denied");
return;
}
boolean inAdminmeanu = true ;
while (inAdminmeanu){
System.out.println(" admin operation ");
System.out.println(" 1.view ticket: ");
System.out.println(" 2.update ticket ");
System.out.println(" 3.back to meanu");
System.out.println(" choose an option: ");
int choice = scanner.nextInt();
scanner.nextLine();
if (choice == 1){
viewTicket(scanner);
} else if ( choice == 2){
updateTicket(scanner);
}else {
System.out.print("invalid option. try again");
}
}
}
private static void viewTicket(Scanner scanner ){
System.out.print("enter ticket number: ");
String ticketnumber = scanner.nextLine();
int index = ticketnumber.indexOf(ticketnumber);
if (index == -1){
System.out.println(" Ticket not found. ");
return;
}
System.out.println("Ticket number : " + ticketNumbers.get(index) + " , Description:" + descriptions.get(index)
+ " , priority: " + porioritries.get(index));
}
private static void updateTicket(Scanner scanner ){
System.out.print("Enter Ticket number : ");
String ticketnum = scanner.nextLine();
int index = ticketnum.indexOf(ticketnum);
if (index == -1) {
System.out.println("ticket not found. ");
return ;
}
System.out.print("Enter New Description: ");
String newDescription = scanner.nextLine();
descriptions.set(index , newDescription);
System.out.println("Ticket update sucessfully !");
}
}