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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
