Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

All required classes are given below:- NEEDS to add the following methods to ConsoleUI class:-////////////////// readChoice() reads the users choice from a Scanner readPerson() reads

All required classes are given below:-

NEEDS to add the following methods to ConsoleUI class:-//////////////////

readChoice() reads the users choice from a Scanner

readPerson() reads in the Person data from a Scanner and returns the new Person

readName() reads in the name of a Person from a Scanner

display() displays a single Persons data

displayAll() displays all people in the database

run() performs the address book functions

displayMenu() displays the available menu

displayErrorMsg() displays the String message passed on the user interface

displayMsg() displays the String message passed on the user interface

NEEDS to add following methods to AddressBook class:-////////////////////

addPerson() reads a Person from the user interface and adds them to the database

deletePerson() reads a Persons name from the user interface and tries to delete them from the database. If not successful, display an error msg on the user interface. If successful, displays the name of the person deleted and the words was deleted successfully on the user interface

findPerson() reads a Persons name from the user interface and tries to find them in the database. If not found the error message No such person is displayed.

displayAll() displays all people in the database on the user interface

display() displays the requested person on the user interface

///////AddressBook.java

public class AddressBook { private final Database database; private final UI ui;

public AddressBook(final UI u) { ui = u; database = new Database(); }

public void addPerson() { }

public void deletePerson() { }

public void findPerson() { }

private boolean remove(final String name) { return (database.removeByName(name) != null); }

private Person search(final String name) { return (database.findByName(name)); }

public void displayAll() { }

private void display(final Person person) { }

}

///////////////ConsoleUI.java

import java.util.Scanner; /** * @author tanus * */ public class ConsoleUI { private final Scanner input; private AddressBook addressBook;

public ConsoleUI() { input = new Scanner(System.in); }

}

///////////////////Database.java

import java.util.ArrayList; import java.util.List;

/** * @author tanus * */ public class Database { private List storage; public Database() { storage = new ArrayList(); } public int add(final Person person) { storage.add(person); return (storage.size() - 1); } public Person[] getAll() { final Person[] copy;

copy = new Person[storage.size()]; storage.toArray(copy); return (copy); } public Person removeByName(final String name) { final Person person; final int index; index = lookupByName(name); if(index > -1) { person = storage.remove(index); } else { person = null; } return (person); } public Person findByName(final String name) { final Person person; final int index; index = lookupByName(name); if(index > -1) { person = storage.get(index); } else { person = null; } return (person); } private int lookupByName(final String name) { int location; int i; location = -1; i = 0; for(final Person person : storage) { if(person.getName().equals(name)) { location = i; break; } i++; } return (location); }

}

////////////Main.java

import java.util.Scanner;

public class Main { public static void main(String[] args) { final UI ui; final AddressBook book; ui = new ConsoleUI(); book = new AddressBook(ui); ui.run(book); } }

///////////////////Person.java

/** * */

/** * @author tanus * */ public class Person { private final String name; private final String phone; public Person(final String nm, final String ph) { name = nm; phone = ph; } public String getName() { return (name); } public String getPhoneNumber() { return (phone); }

}

/////////////UI Interface.java

public interface UI { void display(Person person);

void displayAll(Person[] people);

String readName();

Person readPerson();

void run(AddressBook book);

void displayMsg(String msg);

void displayErrorMsg(String msg); }

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

Step: 3

blur-text-image

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

Temporal Databases Research And Practice Lncs 1399

Authors: Opher Etzion ,Sushil Jajodia ,Suryanarayana Sripada

1st Edition

3540645195, 978-3540645191

More Books

Students also viewed these Databases questions

Question

LO 10-6 How, and how not, to use technology for negative messages.

Answered: 1 week ago

Question

Generally If Drug A is an inducer of Drug B , Drug B levels will

Answered: 1 week ago