Question: Modify the PhoneBookEntry program to display student ID, name and major . Include a UML Diagram with your code and output screenshots submission. import java.util.ArrayList;

Modify the PhoneBookEntry program to display student ID, name and major. Include a UML Diagram with your code and output screenshots submission.

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

public class ArrayListProgram {

public static void main(String[] args) {

String name; long phone_no;

Scanner sc=new Scanner(System.in);

ArrayList al=new ArrayList(); for(int i=0;i<5;i++) {

System.out.println("Person "+(i+1)); System.out.print(" Enter Name:"); name=sc.nextLine();

System.out.print(" Enter Phone No:"); phone_no=sc.nextLong();

al.add(new PhoneBookEntry(name,phone_no)); sc.nextLine(); System.out.println("_________________"); }

System.out.println("Displaying the Names and Phone Numbers :"); Iterator it=al.iterator(); while(it.hasNext()) { PhoneBookEntry pbe=(PhoneBookEntry)it.next(); System.out.println("Name: "+pbe.getName()+" Phone No:"+pbe.getPhoneno()); }

}

}

---------------------------------------------------------------------------------------------------------------------------------------------------------------

public class PhoneBookEntry { //Declaring instance variables private String name; private long phoneno;

//Default Constructor public PhoneBookEntry() { }

//parameterized constructor public PhoneBookEntry(String name, long phoneno) { this.name = name; this.phoneno = phoneno; }

//Getters and setters. 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; }

}

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!