Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The objective of this (JAVA) assignment is to implement a simple menu driver program based on PhoneBookEntry program developed earlier. Declare a class Main that

The objective of this (JAVA) 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();

Phone Book Entry:

public class PhoneBookEntry { private String firstName; private String lastName; private String phoneNumber; public PhoneBookEntry(String firstName, String lastName, String phoneNumber) { this.firstName = firstName; this.lastName = lastName; this.phoneNumber = phoneNumber; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public String getPhoneNumber() { return phoneNumber; } public void setPhoneNumber(String phoneNumber) { this.phoneNumber = phoneNumber; } }

import java.util.ArrayList; public class PhoneBookEntries { public static void main(String[] args) { ArrayList phoneBookEntryList = new ArrayList<>(); phoneBookEntryList.add(new PhoneBookEntry("John", "Smith", "818.555.1234")); phoneBookEntryList.add(new PhoneBookEntry("Jane", "Brown", "818.555.1235")); phoneBookEntryList.add(new PhoneBookEntry("Jose", "Vargas", "818.555.1236")); phoneBookEntryList.add(new PhoneBookEntry("Armen", "Avetian", "818.555.1237")); phoneBookEntryList.add(new PhoneBookEntry("Xin", "Liu", "818.555.1238")); phoneBookEntryList.add(new PhoneBookEntry("James", "White", "818.555.1239")); phoneBookEntryList.add(new PhoneBookEntry("Julie", "McGuiness", "818.555.1240")); phoneBookEntryList.add(new PhoneBookEntry("Juan", "Ballardos", "818.555.1241")); phoneBookEntryList.add(new PhoneBookEntry("Arthur", "London", "818.555.1242")); phoneBookEntryList.add(new PhoneBookEntry("Ashot", "Aghajanian", "818.555.1243")); for(PhoneBookEntry entry: phoneBookEntryList) { System.out.println("First Name: " + entry.getFirstName()); System.out.println("Last Name: " + entry.getLastName()); System.out.println("Phone Number: " + entry.getPhoneNumber()); System.out.println(); } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Murach's SQL Server 2012 For Developers

Authors: Bryan Syverson, Joel Murach, Mike Murach

1st Edition

1890774693, 9781890774691

More Books

Students also viewed these Databases questions

Question

What is a petty cash fund?

Answered: 1 week ago

Question

What is nonverbal communication?

Answered: 1 week ago