-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainMenu.java
More file actions
178 lines (160 loc) · 5.15 KB
/
Copy pathMainMenu.java
File metadata and controls
178 lines (160 loc) · 5.15 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
package phonebookProject;
import java.io.IOException;
import java.util.Scanner;
public class MainMenu {
static Book book = new Book();
public static void main(String[] args) {
displayMenu();
}
// MAIN MENU
public static void displayMenu() {
Scanner in = new Scanner(System.in);
boolean mainLoop = true;
int choice;
while(true) {
System.out.println("----What would you like to do?:----");
System.out.println("1) - Add New Entry");
System.out.println("2) - Search for an Existing Entry");
System.out.println("3) - Delete a Record for a Given Telephone Number");
System.out.println("4) - Update a Record for a Given Telephone Number");
System.out.println("5) - Show all Records in Asc Order");
System.out.println("6) - Exit");
choice = in.nextInt();
// CHOICE SWITCH
switch(choice) {
case 1:
addPerson();
break;
case 2:
findPerson();
break;
case 3:
book.deleteByPhoneNumber();
System.out.println("Contact Has Been Deleted!");
break;
case 4:
try {
book.replaceByPhoneNumber();
System.out.println("Contact Has Been Updated!");
} catch (IOException e) {
e.printStackTrace();
}
break;
case 5:
System.out.println("---Here are your Contacts!---");
book.printAllContacts();
break;
case 6:
System.out.println("------------");
System.out.println("- Goodbye! -");
System.out.println("------------");
System.exit(0);
break;
default :
System.out.println("This is not a valid Menu Option.");
break;
}
}
}
//case 1:
private static void addPerson() {
Scanner input = new Scanner (System.in);
System.out.print("Enter Contact's First Name & Middle Name(s) if Applicable: ");
String firstName = input.nextLine();
System.out.print("Enter Contact's Last Name: ");
String lastName = input.nextLine();
System.out.print("Enter Contact's Phone Number: ");
String phoneNumber = input.nextLine();
System.out.print("Enter Contact's email: ");
String email = input.nextLine();
System.out.print("Enter Contact's Street Number: ");
String streetNum = input.nextLine();
System.out.print("Enter Contact's Street Name: ");
String streetName = input.nextLine();
System.out.print("Enter Contact's City: ");
String city = input.nextLine();
System.out.print("Enter Contact's State & Zip Code if Applicable: ");
String state = input.nextLine();
Address address1 = new Address(streetNum, streetName, city, state);
Person person1 = new Person(firstName, lastName, phoneNumber, email, address1);
book.addContact(person1);
System.out.println("--" + firstName + " " + lastName + " is Now Saved as a Contact!--");
System.out.println();
}
//case 2:
public static void findPerson() {
boolean caseLoop = true;
while(caseLoop) {
System.out.println("---How do you Want to Search?---");
System.out.println("1) - Find with First Name");
System.out.println("2) - Find with Last Name");
System.out.println("3) - Find with Full Name");
System.out.println("4) - Find with Telephone Number");
System.out.println("5) - Search by City");
System.out.println("6) - Search by State");
System.out.println("7) - Exit to Main Menu");
Scanner in = new Scanner(System.in);
String choice;
do {
choice = in.nextLine();
switch(choice) {
case "1":
try {
Person foundPerson = book.findByFirstName();
System.out.println(foundPerson.toString());
} catch (IOException e) {
System.out.println(e.getMessage());
}
break;
case "2":
try {
Person foundPerson = book.findByLastName();
System.out.println(foundPerson.toString());
} catch (IOException e) {
System.out.println(e.getMessage());
}
break;
case "3":
try {
Person foundPerson = book.findByFullName();
System.out.println(foundPerson.toString());
} catch (IOException e) {
System.out.println(e.getMessage());
}
case "4":
try {
Person foundPerson = book.findByPhoneNumber();
System.out.println(foundPerson.toString());
} catch (IOException e) {
System.out.println(e.getMessage());
}
case "5":
try {
Person foundPerson = book.findByCity();
System.out.println(foundPerson.toString());
} catch (IOException e) {
System.out.println(e.getMessage());
}
case "6":
try {
Person foundPerson = book.findByState();
System.out.println(foundPerson.toString());
} catch (IOException e) {
System.out.println(e.getMessage());
}
case "7":
System.out.println("----------------");
System.out.println("- Returning to -");
System.out.println("-- Main Menu! --");
System.out.println("----------------");
caseLoop = false;
break;
default:
System.out.println("Invalid Entry");
}
} while (!choice.equals("1") && !choice.equals("2") && !choice.equals("3") && !choice.equals("4") && !choice.equals("5") && !choice.equals("6"));
System.out.println();
displayMenu();
}
}
}