Write a class named PhoneBookEntry that has fields for person\'s name and phone
ID: 3528037 • Letter: W
Question
Write a class named PhoneBookEntry that has fields for person's name and phone number. The class should have constructure and appropriate accesor and mutator methods. then write a program that creates at least five PhoneBookEntry object and stores them in an ArrayList. Use a loop to display the contents of each object in the ArrayList.Explanation / Answer
>> Write a class named PhoneBookEntry Straightforward. Write a class named PhoneBookEntry. >> that has fields for a person’s name and phone num-ber. String name; String phoneNumber; >> The class should have a constructor public PhoneBookEntry() { } >> and appropriate accessor and mutator methods Accessors = getters. Mutators = setters. Write the methods: getName() setName(String name) getPhoneNumber() setPhoneNumber(String phoneNumber) Then write a program that creates at least five PhoneBookEntry objects and stores them in an ArrayList. public static void main(String[] args) { List list = new ArrayList(); PhoneBookEntry entry1 = new PhoneBookEntry(); entry1.setName("Fred"); entry1.setPhone("123456789"); list.add(entry1); // Rise wash repeat for (PhoneBookEntry entry : list) { System.out.printf("Name = %s Number = %s ", entry.getName(), entry.getPhoneNumber()); } }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.