Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a class named PhoneBookEntry that has fields for a person\'s name and phon

ID: 3636907 • Letter: W

Question

Write a class named PhoneBookEntry that has fields for a person's name and phone number. The class should have a constructor and appropriate accessor and mutator methods. Then write a program that creates at least five PhoneBookEntry objects and stores them in an ArrayList. use a loop[ to display the contents of each object in the ArrayList.

**I have a basis for starting but keep getting multiple errors, want to compare my code to someone who might have already completed a project similar to this. Thanks in advance will rate lifesaver.**

Explanation / Answer

import java.util.*; public class PhoneBookEntry { private String name; private String number; public PhoneBookEntry(String name, String number) { this.name=name; this.number=number; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getNumber() { return number; } public void setNumber(String number) { this.number = number; } public static void main(String[] args) { List phoneList = new ArrayList(); phoneList.add(new PhoneBookEntry("Sue","347-2984")); phoneList.add(new PhoneBookEntry("Rod","384-2898")); phoneList.add(new PhoneBookEntry("Ike","382-9082")); phoneList.add(new PhoneBookEntry("Ann","389-9083")); phoneList.add(new PhoneBookEntry("Sid","982-8984")); for (PhoneBookEntry entry : phoneList) { System.out.println(entry.getName()+" "+entry.getNumber()); } } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote