Question: Java Langauge Mandatory Instruction:Make Two files one regular and one Demo using the code below import java.util.*;//for ArrayList class class PhoneBookEntry{ //PhoneBookEntry Class private String

Java Langauge

Mandatory Instruction:Make Two files one regular and one Demo using the code below

import java.util.*;//for ArrayList class class PhoneBookEntry{ //PhoneBookEntry Class private String name; private String phoneNumber; PhoneBookEntry(){ this.name = ""; this.phoneNumber = ""; } //parameterized constructor PhoneBookEntry(String name,String phoneNumber){ this.name = name; this.phoneNumber = phoneNumber; } //mutator methods. void setName(String name){ this.name = name; } void setPhoneNumber(String phoneNumber){ this.phoneNumber = phoneNumber; } //accessor methods. String getName(){ return this.name; } String getPhoneNumber(){ return this.phoneNumber; } public String toString(){ return "Name: "+getName()+", PhoneBookEntry: "+getPhoneNumber(); } } class Main{//dirver class public static void main(String[] args) { //main method PhoneBookEntry pbe1 = new PhoneBookEntry("John","984-894-8888"); PhoneBookEntry pbe2 = new PhoneBookEntry("Ben Affleck","879-849-8498"); PhoneBookEntry pbe3 = new PhoneBookEntry("Leonard","456-798-2341"); PhoneBookEntry pbe4 = new PhoneBookEntry("Mathew","347-146-3248"); PhoneBookEntry pbe5 = new PhoneBookEntry("Christian","541-387-9812"); // you didn't mention the type of bjects to be stored in the ArrayList // The corect syntax is // ArrayList< Class_Name > arr = nnew ArrayList< Class_Name >(); ArrayList al = new ArrayList();//ArrayList object creation //adding all the PhoneBookEntry Objects ot ArrayList al.add(pbe1); al.add(pbe2); al.add(pbe3); al.add(pbe4); al.add(pbe5); //looping through the al and printing the content in al for(int i=0;i

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!