-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
123 lines (102 loc) · 3.94 KB
/
Main.java
File metadata and controls
123 lines (102 loc) · 3.94 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
package mobilePhone;
import java.util.Scanner;
public class Main {
private static Scanner scanner = new Scanner(System.in);
private static MobilePhone mobilePhone = new MobilePhone();
public static void main(String[] args) {
boolean quit = false;
int choice = 6;
while (!quit) {
System.out.print("Enter your option : ");
choice = scanner.nextInt();
scanner.nextLine();
switch (choice) {
case 0:
quit = true;
break;
case 1:
mobilePhone.printContacts();
break;
case 2:
addMobileContacts();
break;
case 3:
updateContact();
break;
case 4:
removeContact();
break;
case 5:
queryContact();
case 6:
printActions();
break;
}
}
}
private static void printActions() {
System.out.println("\nAvailable Actions:\n press :");
System.out.println("0 - Quit\n" +
"1 - print Contacts\n" +
"2 - Add new Contact\n" +
"3 - to update an existing contact\n" +
"4 - to remove and existing contact\n" +
"5 - query if existing contact exists\n" +
"6 - to print a list of available actions");
System.out.println("Choose your action: ");
}
private static void addMobileContacts() {
System.out.print("Enter name : ");
String name = scanner.nextLine();
System.out.print("Enter Mobile number : ");
String number = scanner.nextLine();
Contact contact = Contact.createContact(name, number);
if (mobilePhone.AddContact(contact)) {
System.out.println("new contact added: " + name + ", phone = +" + number);
} else {
System.out.println("Cannot add, " + name + " already on file");
}
}
private static void updateContact() {
System.out.println("Enter existing contact name ");
String name = scanner.nextLine();
Contact existingContactRecord = mobilePhone.queryContact(name);
if (existingContactRecord == null) {
System.out.println("Contact not Found");
return;
}
System.out.println("Enter new Contact name: ");
String newName = scanner.nextLine();
System.out.println("Enter new Contact Phone Number: ");
String newPhone = scanner.nextLine();
Contact newContact = new Contact(newName, newPhone);
if (mobilePhone.updateContact(existingContactRecord, newContact)) {
System.out.println("Successfully update record");
} else {
System.out.println("Error updating record");
}
}
private static void removeContact() {
System.out.println("Enter existing contact name ");
String name = scanner.nextLine();
Contact existingContactRecord = mobilePhone.queryContact(name);
if (existingContactRecord == null) {
System.out.println("Contact not Found.");
}
if (mobilePhone.removeContact(existingContactRecord)) {
System.out.println("successfully Deleted");
} else {
System.out.println("error deleting Record");
}
}
private static void queryContact() {
System.out.println("Enter existing contact name ");
String name = scanner.nextLine();
Contact existingContactRecord = mobilePhone.queryContact(name);
if (existingContactRecord == null) {
System.out.println("Contact not Found");
return;
}
System.out.println("Name: " + existingContactRecord.getName() + " phone number is " + existingContactRecord.getPhoneNumber());
}
}