Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Project 4 Write a class named PhoneEntry to represent a name and phone number. T

ID: 3554163 • Letter: P

Question

Project 4

Write a class named PhoneEntry to represent a name and phone number. Then, write a separate driver program and name it Phone.java to declare and instantiate five phone entries and to print them out.

The PhoneEntry class should be written to the following specifications:

Be sure to add comments with a description of the program, your name, the date, and a short comment for each variable declaration. Also, add comments for each method describing the method and commenting all parameters, return values and local variables. Also be sure to use good variable names.

Save your two PhoneEntry.java and Phone.java (driver program) in the Project 4 drop box and turn in a printed copy as well.

Explanation / Answer

//PhoneEntry.java


public class PhoneEntry {

String first, last;

int phone;

public PhoneEntry(){

first = "";

last = "";

phone = 000000000;

}

public PhoneEntry(String f, String l, int p){

first = f;

last = l;

phone = p;

}

public void setFirst(String f){

first = f;

}

public void setLast(String l){

last = l;

}

public void setPhone(int p){

phone = p;

}

public String getFirst(){

return first;

}

public String getLast(){

return last;

}

public int getPhone(){

return phone;

}

public String toString(){

return "First name: " + getFirst() + " Last name: " + getLast() + " Phone number: " + getPhone() + " ";

}

}




// Phone.java


public class Phone {

public static void main(String args[]){

PhoneEntry obj1 = new PhoneEntry("Dexter", "Morgan", 999888777);

PhoneEntry obj2 = new PhoneEntry("Slim", "Shady", 927831123);

PhoneEntry obj3 = new PhoneEntry("Random", "Name", 000000000);

PhoneEntry obj4 = new PhoneEntry("Java", "Language", 909090909);

PhoneEntry obj5 = new PhoneEntry("My", "Name", 123456789);

System.out.println(obj1.toString());

System.out.println(obj2.toString());

System.out.println(obj3.toString());

System.out.println(obj4.toString());

System.out.println(obj5.toString());

}

}