Hello.. I'm new with java and have some problem with my assignment. I want to write a class named phoneBookEntry that has field for a person name and phone number. The class should have a constructor and appropriate accessor and mutator method. Then, write a main class that create five phoneBookEntry objects and store them in an arraylist. Use a loop to display the contents of each object in the arraylist.
My problem is my code can't run properly. I dont know where is my fault.
Is there anyone can check my code??? Please help me. Thank You
This is my code.
public class phoneBookEntry {
/** Creates a new instance of Main */
private String name;
private String number;
public phoneBookEntry() {
name = null;
name = null;
}
public phoneBookEntry (String phoneName, String phoneNumber){
name = phoneName;
number = phoneNumber;
}
public void setName (String phoneName){
name = phoneName;
}
public String getName (){
return name;
}
public void setNumber(String phoneNumber){
number = phoneNumber;
}
public String getNumber(){
return number;
}
}
I make two classes. This is for other class.
import java.util.Scanner;
import java.util.ArrayList;
public class NewClass {
/** Creates a new instance of NewClass */
public static void main (String []args){
phoneBookEntry bookEntry1 = new phoneBookEntry ();
ArrayList <phoneBookEntry> phoneName = new ArrayList <phoneBookEntry>(5);
ArrayList <phoneBookEntry> phoneNumber = new ArrayList <phoneBookEntry> (5);
Scanner input = new Scanner (System.in);
for (int x = 0; x < phoneName.size(); x++){
System.out.println ("Enter the identity ");
System.out.println ("Name : ");
bookEntry1.setName(input.nextLine());
for (int y = 0; y < phoneNumber.size(); y++){
System.out.println("Number : ");
bookEntry1.setNumber(input.nextLine());
}
}
for (int z = 0; z< phoneName.size(); z++){
System.out.println("name" +bookEntry1.getName()+ "and number "+ bookEntry1.getNumber());
}
}
}