Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I edited some parts of the code but not sure if they are correct or not. Also need to add more code but I do

I edited some parts of the code but not sure if they are correct or not. Also need to add more code but I do not know what to do.

This is all of the things that our teacher posted. Nothing to add to this.

For this assignment you will use an ArrayList to create an address book.

Specifications

Download the three starter classes from Github and fill in the missing methods, as well as the Runner. The Runner should ask for input so that Contacts can be created and then added, accessed, and removed. Optionally, you can also add a method to edit a Contact.

Sample Outputs

Would you like to (1) add, (2) access, (3) show list, or (4) delete? 1 What is the name? Mr. King Would you like to (1) add, (2) access, (3) show list, or (4) delete? 1 What is the name? Jane Doe Would you like to (1) add, (2) access, (3) show list, or (4) delete? 1 What is the name? John Doe Would you like to (1) add, (2) access, (3) show list, or (4) delete? 3 Number of contacts: 3 ------------------------- | Jane Dean | | M: 4085555557 | | W: 4085356502 | | E: jdean@sjusd.org | ------------------------- ------------------------- | John Doe | | M: 4085555556 | | W: 4085356501 | | E: jdoe@sjusd.org | ------------------------- ------------------------- | Mr. King | | M: 4085555555 | | W: 4085356500 | | E: cking@sjusd.org | -------------------------

-------------------------------------------------------------

import java.util.List; import java.util.ArrayList; 
public class AddressBook { List book; /** * Constructs AddressBook object (initializes List as an ArrayList) */ public AddressBook() { book = new ArrayList(); } /** * * @param c * * Add Contact c into this AddressBook (alphabetically) */ public void add(Contact c) { book.add(c); } /** * * @param fn * @param ln * * Removes Contact with given first and last name. Prints error message if Contact does not exist. */ public void remove(String fn, String ln) { book.remove(String } /** * * @param fn * @param ln * @return Contact with given first and last name. Returns null if not found. */ public Contact get(String fn, String ln) { int i = getIndex(fn, ln); // check that i is not -1 Contact c = book.get(i); return c; } /** * * @param fn * @param ln * @return index of Contact with given first and last name. Returns -1 if not found. * * Uses binary search. */ public int getIndex(String fn, String ln) { int lo = 0; int hi = book.size() - 1; while (lo <= hi) { int mid = lo + (hi - lo) / 2; if(ln.compareTo(book.get(mid).getLastName()) < 0) { hi = mid - 1; } else if(ln.compareTo(book.get(mid).getLastName()) > 0) { lo = mid + 1; } else { return mid; } } return -1; } /** * Prints all Contacts in this AddressBook. */ public void printList() { } @Override public String toString() { String s = ""; for(Contact c: book) { s += c; s += " "; } return s; } }

-----------------------------------------------------------

public class Contact { private String last, first, work, mobile, email; /** * * @param first * * Constructs a Contact object with a first name and sets all other fields to blank. */ public Contact(String first) { /*this.first = first; last = ""; work = ""; mobile = ""; email = "";*/ this(first, "", "", "", ""); } /** * * @param first * @param last * @param work * @param mobile * @param email * * Constructs a Contact object with the given information. */ public Contact(String first, String last, String work, String mobile, String email) { this.first = first; this.last = last; this.work = work; this.mobile = mobile; this.email = email; } /** * * @return last name of this Contact */ public String getLastName() { } /** * * @return first name of this Contact */ public String getFirstName() { } /** * * @param c * @return Returns true if this Contact is the same as Contact c. Returns false otherwise. */ public boolean equals(Contact c) { } @Override public String toString() { String s = ""; s += "------------------------- "; s += "| " + first + " " + last + "\t\t| "; s += "| M: " + mobile + "\t\t| "; s += "| W: " + work + "\t\t| "; s += "| E: " + email + "\t| "; s += "------------------------- "; return s; } }

------------------------------------------------------

public class Runner { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("Would you like to (1) add, (2) access, (3) show list, or (4) delete?"); } }

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

Master The Art Of Data Storytelling With Visualizations

Authors: Alexander N Donovan

1st Edition

B0CNMD9QRD, 979-8867864248

More Books

Students also viewed these Databases questions