-
Notifications
You must be signed in to change notification settings - Fork 0
/
GuestList.java
66 lines (58 loc) · 2.08 KB
/
GuestList.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
import java.util.Scanner;
public class GuestList {
public static void main(String[] args) {
String[] guests = new String[10];
Scanner scanner = new Scanner(System.in);
guests[0] = "Jacob";
guests[1] = "Edward";
guests[2] = "Rose";
guests[3] = "Molly";
guests[4] = "Christopher";
do {
System.out.println();
System.out.println("1 - Display All Guests");
System.out.println("2 - Add Guest");
System.out.println("3 - Remove Guest");
System.out.println("4 - Exit");
System.out.print("Option: ");
int option = scanner.nextInt();
System.out.println();
if (option == 1) {
for (int i = 0; i < guests.length; i++) {
if (guests[i] != null) {
System.out.println(guests[i]);
}
}
} else if (option == 2) {
for (int i = 0; i < guests.length; i++) {
if (guests[i] == null) {
System.out.print("Name: ");
guests[i] = scanner.next();
break;
}
}
} else if (option == 3) {
System.out.print("Name: ");
String name = scanner.next();
for (int i = 0; i < guests.length; i++) {
if (guests[i] != null && guests[i].equals(name)) {
guests[i] = null;
break;
}
}
String[] temp = new String[guests.length];
int it = 0;
for (int i = 0; i < guests.length; i++) {
if (guests[i] != null) {
temp[it] = guests[i];
it++;
}
}
guests = temp;
} else if (option == 4) {
System.out.println("Exiting...");
break;
}
} while (true);
}
}