Question
Java The objective of this assignment is to implement a simple menu driver program based on PhoneBookEntry program developed earlier. Declare a class Main that
Java
The objective of this assignment is to implement a simple menu driver program based on PhoneBookEntry program developed earlier. Declare a class Main that contains the main method and is the entry point to the program. PhoneBookEntries are stored in a CSV file that needs to be loaded at the beginning of the execution and saved at the end of the execution. The program should allow a case-insensitive search by any substring of first name, last name, or phone number (just like smartphones). The program should also allow for new entry to be added, and an existing entry to be deleted by entry number.
Here is what the menu will look like:
Phone Book
==========
1. Find an entry
2. Add a new entry
3. Remove an entry
4. Display all
5. Exit
Enter choice:
Hints:
1. How to read a CSV file?
There are two methods.
Method 1. Use delimiters in Scanner object to read one token at a time. Here is some sample code:
File phoneBookFile = new File("phonebook.csv"); Scanner inputFile = new Scanner(phoneBookFile); inputFile.useDelimiter("[, \t]+"); int i = 0; while(inputFile.hasNext()) {
String firstname = inputFile.next(); String lastname = inputFile.next(); String phoneNumber = inputFile.next(); System.out.println("Entry #" + ++i + ": first name: " + firstname + ", last name: " + lastname + ", phone number: " + phoneNumber);
}
inputFile.close();
Method 2. Read a full line and then split it into individual tokens as an array of Strings. Here is some sample code:
File phoneBookFile = new File("phonebook.csv");
Scanner inputFile = new Scanner(phoneBookFile);
int i = 0;
while(inputFile.hasNext()) {
String line = inputFile.nextLine();
String[] entry = line.split(",");
System.out.println("Entry #" + ++i + ": first name: " + entry[0] + ", last name: " + entry[1] + ", phone number: " + entry[2]);
}
inputFile.close();
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started