Question: **Java Language only** (Direction of code :Write a class named PhoneBookEntry that has fields for a persons name and phone number. The class should have

**Java Language only**

(Direction of code :Write a class named PhoneBookEntry that has fields for a persons 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.)

Instructions:Take this code ((make sure it works in textpad, currently showing error for two public classes!!)) and put detailed comments on it and a uml diagram at the top of the code in comment form.

I Will Thumbs Up Thanks!!

import java.util.ArrayList; import java.util.Scanner;

public class PhoneBookEntryTest {

public static void main(String[] args) { ArrayList list = new ArrayList(); Scanner scan = new Scanner(System.in); for(int i=0; i<5; i++){ System.out.print("Enter Person Name: "); String name = scan.nextLine(); System.out.print("Enter Phone Number: "); long phoneNo = scan.nextLong(); scan.nextLine(); PhoneBookEntry p = new PhoneBookEntry(name, phoneNo); list.add(p); } System.out.println("--------------------------------"); for(PhoneBookEntry p: list){ System.out.println(p.toString()); } }

}

public class PhoneBookEntry { private String name; private long phoneNo; public PhoneBookEntry (String name, long phneNo){ this.name = name; this.phoneNo = phneNo; } public String getName() { return name; } public void setName(String name) { this.name = name; } public long getPhoneNo() { return phoneNo; } public void setPhoneNo(long phoneNo) { this.phoneNo = phoneNo; } public String toString(){ return "Person Name: "+getName()+" Phone Number: "+getPhoneNo(); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!