Exemple #1
0
  public static void main(String[] args) {
    FileHandler fh = new FileHandler();
    Contact c = new Contact();
    List<Contact> contactList = new ArrayList<Contact>();

    String[] fields = fh.readFile(new File("/names.txt"));
    for (int i = 0; i < fields.length; i++) {
      if (!(fields[i].equals("-----"))) {
        c.setFirstName(fields[i++]);
        c.setLastName(fields[i++]);
        c.setAddress(fields[i++]);
        c.setCity(fields[i++]);
        c.setState(fields[i++]);
        c.setZip(fields[i++]);
        c.setEmail(fields[i++]);
        c.setPhone(fields[i++]);
      }
      contactList.add(c);
    }
    for (int i = 0; i < contactList.size(); i++) {
      System.out.println(
          contactList.get(i).getFirstName() + " " + contactList.get(i).getLastName());
      System.out.println(contactList.get(i).getAddress());
      System.out.println(
          contactList.get(i).getCity()
              + ", "
              + contactList.get(i).getState()
              + "  "
              + contactList.get(i).getZip());
      System.out.println(contactList.get(i).getPhone());
      System.out.println(contactList.get(i).getEmail());
      System.out.println();
    }
  }
Exemple #2
0
  public static void main(String[] args) {
    Contact testContact = new Contact();
    String input = null; // variable for users input
    Scanner keyboard = new Scanner(System.in); // creates Scanner Object

    System.out.print("Enter the last name: ");
    input = keyboard.nextLine(); // changes value of input
    testContact.setLastName(input); // sends input to setLastName method to be validated

    System.out.println("Last name: " + testContact.getLastName()); // displays users input

    System.out.print("Enter the first name: ");
    input = keyboard.nextLine(); // changes value of input
    testContact.setFirstName(input); // sends input to setFirstName method to be validated

    System.out.println("First name: " + testContact.getFirstName()); // displays users input

    System.out.print("Enter the Middle name: ");
    input = keyboard.nextLine(); // changes value of input
    testContact.setMiddleName(input); // sends input to setMiddleName method to be validated

    System.out.println("Middle name: " + testContact.getMiddleName()); // displays users input

    System.out.print("Enter the prefix (if you have none, input none): ");
    input = keyboard.nextLine(); // changes value of input
    testContact.setPrefix(input); // sends input to setPrefix method to be validated

    System.out.println("Prefix: " + testContact.getPrefix()); // displays users input

    System.out.print("Enter the phone number: ");
    input = keyboard.nextLine(); // changes value of input
    testContact.setPhoneNum(input); // sends input to setPhoneNum method to be validated

    System.out.println("Phone number: " + testContact.getPhoneNum()); // displays users input

    System.out.print("Enter the Email: ");
    input = keyboard.nextLine(); // changes value of input
    testContact.setEmail(input); // sends input to setEmail method to be validated

    System.out.println("Email: " + testContact.getEmail()); // displays users input

    System.out.print("Enter the Street: ");
    input = keyboard.nextLine(); // changes value of input
    testContact.setStreet(input); // sends input to setStreet method to be validated

    System.out.println("Street: " + testContact.getEmail()); // displays users input

    System.out.print("Enter the City: ");
    input = keyboard.nextLine(); // changes value of input
    testContact.setCity(input); // sends input to setCity method to be validated

    System.out.println("City: " + testContact.getCity()); // displays users input

    System.out.print("Enter the State: ");
    input = keyboard.nextLine(); // changes value of input
    testContact.setState(input); // sends input to setState method to be validated

    System.out.println("State: " + testContact.getState()); // displays users input

    System.out.print("Enter the Zip Code: ");
    input = keyboard.nextLine(); // changes value of input
    testContact.setZipCode(input); // sends input to setZipCode method to be validated

    System.out.println("Zip code: " + testContact.getZipCode()); // displays users input

    System.out.print("Enter the Occupation: ");
    input = keyboard.nextLine(); // changes value of input
    testContact.setOcupation(input); // sends input to setOccupation method to be validated

    System.out.println("Occupation: " + testContact.getOccupation()); // displays users input
  }