Please help with this java program. Write a class named PhoneBookEntry that has
ID: 3579420 • Letter: P
Question
Please help with this java program.
Write a class named PhoneBookEntry that has fields for a student’s name, phone number and major. The class should have a constructor and appropriate accessor and mutator methods, and Equals() method and a toString() method.
Create a program that creates at least five PhoneBookEntry objects and stores them in an ArrayList. Use the ArrayList class Iterator to find one of the students in the list and displays their data. Use the ArrayList classListIterator to search the students in the list for a computer science major. Display the CS majors.
Explanation / Answer
class phonebookentry{
string studentname;
int phoneno;
string major;
phonebookenrty(string studentname, int phoneno, string major)
{
this.studentname=studentname;
this.phoneno = phoneno;
this.major=major;
}
}
import java.util.*;
public class test{
public static void main(string [] args)
{
scanner sc = new scanner(sysem.in);
for(i=0;i<6;i++)
{
string studentname[i] = sc.nextstring(system.in);
int phoneno [i]= sc.nextint(system.in);
string major[i] = sc.nextstring(system.in);
phonebookentry ph[i]= new phonebook(studentname[i],phoneno [i],major[i])
}
ArrayList <phonebookentry> al = new ArrayList <phonebookentry>();
for(i=0;i<6;i++)
{
al.add(phonebookentry ph[i]);
}
iterator itr= al.iterator();
while(itr.HasNext())
{
phonebookenrty ph =(phonebookenrty)itr.next();
for(i=0;i<6;i++)
{
if( ph.major[i].Equals(cs){
system.out.println(ph.studentname[i]+ " " ph.phoneno[i]+" " ph.major[i]);
}
}
}
}