import java.util.ArrayList;
import java.util.Scanner;
public class Main {
String firstName;
String lastName;
String phoneNumber;
String email;
public Main() {
this.firstName = "";
this.lastName = "";
this.phoneNumber = "";
this.email = "";
}
public Main(String fName, String lName, String phone, String email) {
this.firstName = fName;
this.lastName = lName;
this.phoneNumber = phone;
this.email = email;
}
public void setFirstName(String fName) {
this.firstName = fName;
}
public void setLastName(String lName) {
this.lastName = lName;
}
public void setNumber(String phone) {
this.phoneNumber = phone;
}
public void setEmail(String email) {
this.email = email;
}
public String getFirstName() {
return this.firstName;
}
public String getLastName() {
return this.lastName;
}
public String getNumber() {
return this.phoneNumber;
}
public String getEmail() {
return this.email;
}
public static void main(String args[]) {
ArrayList<Main> Book = new ArrayList<Main>();
while (true) {
System.out.println("Contact book menu");
System.out.println("-------------------------------------------");
System.out.println("Press 1: Add a new contact.");
System.out.println("Press 2: Display all contacts.");
System.out.println("Press 3: Seach contacts.");
System.out.println("Press 4: Delete a contact.");
System.out.println("Press 5: Exit menu.");
Scanner keyboard = new Scanner(System.in);
int input = keyboard.nextInt();
switch (input) {
case 1:
Main A = new Main();
System.out.println("Enter the first name: ");
A.firstName = keyboard.next();
System.out.println("Enter the last name: ");
A.lastName = keyboard.next();
System.out.println("Enter the phone number: ");
A.phoneNumber = keyboard.next();
System.out.println("Enter the e-mail address: ");
A.email = keyboard.next();
break;
case 2:
for (Main A : Book)
Â;
{
System.out.println("Name: " + A.firstName + " " + A.lastName + "\nPhone: " + A.phoneNumber + "\nE-mail: " + A.email);
}
break;
case 3:
System.out.println("Enter the contact name you wish to search for: ");
 Â;
 Â;
 Â;
 Â;
String str = keyboard.next();
 Â;
 Â;
 Â;
 Â;
Â
Â;
 Â;
 Â;
 Â;
 Â;
 Â;
Â;
for (Main A : Book)
 Â;
 Â;
 Â;
 Â;
 Â;
 Â;
{
 Â;
 Â;
 Â;
 Â;
 Â;
 Â;
 Â;
 Â;
if (A.firstName.indexOf(str) != -1) Â;
{
 Â;
 Â;
 Â;
 Â;
 Â;
 Â;
 Â;
 Â;
 Â;
System.out.println(A);
 Â;
 Â;
 Â;
 Â;
 Â;
 Â;
 Â;
 Â;
}
if (A.lastName.indexOf(str) != -1) {
 Â;
System.out.println(A);
} else if (A.email.indexOf(str) != -1) {
 Â;
System.out.println(A);
} else {
 Â;
 Â;
 Â;
 Â;
 Â;
 Â;
 Â;
 Â;
 Â;
System.out.println("No results.");
 Â;
 Â;
 Â;
 Â;
 Â;
 Â;
 Â;
 Â;
}
 Â;
 Â;
 Â;
 Â;
 Â;
 Â;
}
break;
case 4:
System.out.println("Enter the contact name you wish to delete: ");
 Â;
 Â;
 Â;
 Â;
 Â;
 Â;
for (Main A : Book)
 Â;
 Â;
 Â;
 Â;
 Â;
 Â;
{
 Â;
 Â;
 Â;
 Â;
 Â;
 Â;
 Â;
 Â;
if (A.firstName.indexOf(str) != -1) Â;
{
 Â;
 Â;
 Â;
 Â;
 Â;
 Â;
 Â;
 Â;
 Â;
System.out.println(A);
 Â;
 Â;
 Â;
 Â;
 Â;
 Â;
 Â;
 Â;
}
else if (A.lastName.indexOf(str) != -1){
 Â;
System.out.println(A);
} else if (A.email.indexOf(str) != -1) {
 Â;
System.out.println(A);
} else {
 Â;
 Â;
 Â;
 Â;
 Â;
 Â;
 Â;
 Â;
 Â;
System.out.println("No results.");
 Â;
 Â;
 Â;
 Â;
 Â;
 Â;
 Â;
 Â;
}
System.out.println("Are you sure you want to delete? (y/n)");
String deletion = keyboard.next();
if (deletion == "y") {
 Â;
 Â;
 Â;
Book.remove(A);
} else {
 Â;
System.out.println("The contact(s) was not removed.");
}
 Â;
 Â;
 Â;
 Â;
 Â;
 Â;
}
break;
 Â;
 Â;
case 5:
break;
 Â;
}
}
}
}