Notes 20240502194241
Notes 20240502194241
02 7:42 PM
Hey
import java.io.*;
import java.util.*;
@Override
public String toString() {
return "Name: " + name + ", Phone Number: " + phoneNumber;
}
}
public AddressBook() {
contacts = new ArrayList<>();
loadContacts();
}
while (true) {
System.out.println("1. Add Contact");
System.out.println("2. Display Contacts");
System.out.println("3. Exit");
System.out.print("Enter your choice: ");
switch (choice) {
case 1:
System.out.print("Enter name: ");
String name = scanner.nextLine();
System.out.print("Enter phone number: ");
String phoneNumber = scanner.nextLine();
Contact newContact = new Contact(name, phoneNumber);
addressBook.addContact(newContact);
System.out.println("Contact added successfully!");
break;
case 2:
System.out.println("Contacts:");
addressBook.displayContacts();
break;
case 3:
System.out.println("Exiting...");
System.exit(0);
default:
System.out.println("Invalid choice. Please enter a number
between 1 and 3.");
}
}
}
}