I can't figure out what I did wrong here. I feel as though it's very obvious, but I can't figure it out for the life of me right now. Any help would be greatly appreciated.
/** The class, PhoneBookEntry, has fields for a person's name and number. */ public class PhoneBookEntry { private String names; private String phoneNumber; public PhoneBookEntry(String name, String number) { names = name; phoneNumber = number; } public void setName(String name) { names = name; } public String getName() { return names; } public void setNumber(String number) { phoneNumber = number; } public String getNumber() { return phoneNumber; } }
/** The program, PhoneBook, creates 5 PhoneBookEntry objects and stores them in an ArrayList. A loop then displays the contents in the ArrayList. */ import java.util.ArrayList; public class PhoneBook { public static void main(String[] args) { ArrayList<PhoneBookEntry> list = new ArrayList<PhoneBookEntry>(); list.setName(new PhoneBookEntry("Steve")); list.setNumber(new PhoneBookEntry("(908)651-9685")); list.setName(new PhoneBookEntry("Rachel")); list.setNumber(new PhoneBookEntry("(732)855-4658")); list.setName(new PhoneBookEntry("John")); list.setNumber(new PhoneBookEntry("(732)743-8102")); list.setName(new PhoneBookEntry("Tommy")); list.setNumber(new PhoneBookEntry("(732)421-0332")); list.setName(new PhoneBookEntry("Amanda")); list.setNumber(new PhoneBookEntry("(732)947-5245")); for(PhoneBookEntry object : list) { System.out.println("Name: " + " " + "Number: "); System.out.println(list.getName() + " " + list.getNumber()); } } }
Thanks in advance.