// Arup Guha
// 7/5/04 
// PhoneBookEntry class for 2004 BHCSI Pre-Test Program.
// This class manages a simple entry for a PhoneBook. It stores a first
// name, last name and a phone number.

import java.io.*;
import java.util.Scanner;

public class PhoneBookEntry {

  private String firstName;
  private String lastName;
  private int number;

  public PhoneBookEntry(String fn, String ln, int num) {
    firstName = fn;
    lastName = ln;
    number = num;
  }

  // Changes the phone number for the current object to newnum.
  public void changeNumber(int newnum) {
    number = newnum;
  }

  // Changes the last name for the current object to newlastname.
  public void changeLastName(String newlastname) {
    lastName = newlastname;
  }

  // Returns a string representation of the object.
  public String toString() {
    return firstName+"\t"+lastName+"\t"+(number/10000)+"-"+(number%10000);
  }

  // Returns true iff ln is the same as the last name of the current
  // object.
  public boolean sameLastName(String ln) {
    return (lastName.equals(ln));
  }

  // Prompts the user for information about a PhoneBookEntry object and
  // returns a newly created object based on that information.
  public static PhoneBookEntry getEntry() throws IOException {

    Scanner stdin = new Scanner(System.in);
    
    System.out.println("What is the first name of the entry?");
    String fn = stdin.next();
    System.out.println("What is the last name of the entry?");
    String ln = stdin.next();
    System.out.println("What is the phone number of this entry?");
    int num = stdin.nextInt();

    return new PhoneBookEntry(fn, ln, num);
  }
}
