// method overloading

class Person {

  private String firstname;
  private String lastname;

  /****************
   * constructors *
   ****************/
  
  public Person() { 
  } // constructor: 0 arguments
  
  public Person(String fn, String ln) {
    firstname = fn;
    lastname = ln;
  } // constructor: 2 arguments
    
  /**************************
   * utility methods (hide) *
   **************************/
  
  // this method adds a string to blanks spaces followed by another string
  
  private String addstrings(int spaces, String start, String stop) {
    
    // create middle string of blank spaces
    String middle = "";
    for(int s = 1; s <= spaces; s++)
      middle = middle + " ";
    return start + middle + stop;
    
  } // method addstrings
  
  /*******************
   * service methods *
   *******************/
  
  public void set_firstname(String name) {
    firstname = name;
  } // method set_firstname
  
  public void set_lastname(String name) {
    lastname = name;
  } // method set_lastname
  
  public String get_firstname() {
    return firstname;
  } // method get_firstname

  public String get_lastname() {
    return lastname;
  } // method get_lastname
  
  /**********************
   * Overloaded Methods *
   **********************/
  
  // fullname: 1 space between first and last names:
  public String get_fullname() {
    String fn = get_firstname();
    String ln = get_lastname();
    int spaces = 1;
    return addstrings(spaces, fn, ln);
  } // method get_fullname (0 arguments)
  
  // fullname: arbitrary # of spaces between first and last names
  public String get_fullname(int spaces) {
    String fn = get_firstname();
    String ln = get_lastname();
    return addstrings(spaces, fn, ln);
  } // method get_fullname (1 argument)
  
  
  // fullname: insert middle name
  public String get_fullname(String middle) {
    String fn = get_firstname();
    String ln = get_lastname();
    return fn+" "+middle+" "+ln;
  } // method get_fullname (1 argument)
  
} // class Person

public class overload {
  
  public static void main(String args[]) {
    
    // NEW OBJECTS
    // use constructor Person()
    Person dis = new Person();
    
    // Assign values in object dis
    /* System.out.println(dis.firstname); */  // this line wouldn't compile
    
    dis.set_firstname("David");
    dis.set_lastname("Schwartz");
    
    // Retrieve individual values from dis
    
    System.out.println(dis.get_firstname());
    System.out.println(dis.get_lastname());
    
    // Determine fullname by three differebnt (and overloaded) methods
    
    System.out.println("Test1: " + dis.get_fullname());
    System.out.println("Test2: " + dis.get_fullname(2));
    System.out.println("Test3: " + dis.get_fullname("Ira"));
    
  } // method main
  
} // class overload

/* OUTPUT

David
Schwartz
Test1: David Schwartz
Test2: David  Schwartz
Test3: David Ira Schwartz
*/
