This exercise's objective is to gain some more experience in working with classes.
Show the work that you do to the GTA.
import java.io.*; class Entry{ // Declare instance variables here private String ??? private String ??? private String ??? private String ??? // Constructor method public Entry(String firstname, String lastname){ ??? } public void printEntry(){ System.out.println(last + ", " + first); ??? ??? } public void setPhone(String phone){ ??? } public String getLastFirst(){ return ??? + ", " + ???; } public String getFirst(){ return ???; } }
Second, complete the constructor. The constructor will need to take two String references as parameters: first and last names. Be careful not to use the same identifiers as your instance variable names or you will hide them. The constructor must initialize the two instance variables for the name.
Third, you will need to complete or add definitions for the following methods to the class:import java.io.File; import java.util.Scanner; // Program Address // Author:You can see that this class utilizes the Entry class and its methods that you just created.// Purpose: Test program for Entry class - reads in three names and builds Entry objects // Modified by: Mir Farooq Ali class Address { public static void main (String arg[]) throws Exception { Entry n1, n2, n3, n4; String printing; String filename = "Address.Input.txt"; Scanner inFile; inFile = new Scanner (new File(filename)); n1 = getInfo(inFile); n2 = getInfo(inFile); n3 = getInfo(inFile); n4 = getInfo(inFile); n1.printEntry(); System.out.println(); System.out.println(n2.getLastFirst()); System.out.println(n2.getEmail()); System.out.println(); System.out.println(n3.getFirstLast()); System.out.println(n3.getPhone()); System.out.println(); System.out.println(n4.getLast() + ", " + n4.getFirst()); } //end main // Method: getInfo // Purpose: reads a single person's address information and creates an Entry object public static Entry getInfo(Scanner inFile) throws Exception { String first, last, phone, email; // stores entry information Entry entry = null; first = inFile.next(); //read first name last = inFile.next(); // read last name phone = inFile.next(); // read phone number email = inFile.next(); // read email entry = new Entry(first, last); //create entry with name entry.setPhone(phone); //add phone and email entry.setEmail(email); return entry; } //end getInfo } //end Address class