Well,I was hoping I could avoid this but here I am
My problem is the following. In this Class person
class Person { final String name; final String address; final String phoneNr; Person(String name, String address, String phoneNr) { this.name = name; this.address = address; this.phoneNr = phoneNr; } @Override public String toString() { return String.format("%-10s, %-20s, %-10s", name, address, phoneNr); } }
There is this toString method.Now the instructions in the assignment say to rewrite it in the PhoneBookList class.
class PhoneBookList implements PhoneBook { private int size = 0; Node head = null; private static final class Node { final Person person; Node next; Node(Person person) { this.person = person; } } public boolean insert(Person person) { Node n = new Node(person); if (head == null) { head = n; size++; return true; } Node current = head; Node prev = null; int comparison; while (current != null) { comparison = person.name.compareTo(current.person.name); if (comparison == 0) { return false; } else if (comparison > 0) { if (current.next == null) { current.next = n; break; } current = current.next; } else { if (prev == null) { Node oldHead = head; head = n; head.next = oldHead; break; } prev.next = n; n.next = current; break; } prev = current; current = current.next; } size++; return true; } public int size() { Out.formatln("The phone book has: %d entries",size ); return size; } public boolean delete(String name) { if (head == null) { return false; } if (head.person.name.compareTo(name) == 0) { head = head.next; size--; return true; } Node current = head; Node prev = head; while (current != null) { if (current.person.name.compareTo(name) == 0) { prev.next = current.next; size--; return true; } prev = current; current = current.next; } return false; } public Person lookup(String name) { if (head == null) { return null; } Node current = head; while (current != null) { if (current.person.name.compareTo(name)==0) { return current.person; } current = current.next; } return null; } public String toString() { return String.format("%-10s, %-20s, %-10s", name, address, phoneNr); } } }
Now when I do this I get an compile error saying it cannot find these 3 parameters (name,address,phonenr). How do I implement this method?