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

**Java Language only** (Direction of code :Write a class named PhoneBookEntry th

ID: 3750796 • Letter: #

Question

**Java Language only**

(Direction of code :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.)

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<PhoneBookEntry> list = new ArrayList<PhoneBookEntry>();
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();
}
}

Explanation / Answer

Ideally as questions says you should create two files "PhoneBookEntry.java" and "PhoneBookEntryTest.java" then you will not get any error and you can run "PhoneBookEntryTest.java" from command prompt as that class has main method.

If you still want to save both the classes in single file then you can have only single public class in one file so remove public keyword from "PhoneBookEntry" class. Below are the classes with small modifications: