1 /* 2 * A class that models a person in terms of 5 properties: 3 * 1. First Name (String) 4 * 2. Last Name (String) 5 * 3. Month (int) 6 * 4. Day (int) 7 * 5. Year (int) 8 */ 9 10 package people; 11 12 public class Person implements PersonSpecification{ 13 14 // Private instance variables 15 private String firstName; 16 private String lastName; 17 private int month; 18 private int day; 19 private int year; 20 21 // Constructors 22 public Person(String name, int month, int day, int year) { 23 int space = name.indexOf(" "); 24 firstName = name.substring(0, space); //gets the first name from the full name and binds to the private instance variable 25 lastName = name.substring(space + 1); //gets the last name from the full name and binds to the private instance variable 26 this.month = month; //use "this" keyword to disambiguate named instance variables and parameters 27 this.day = day; //use "this" keyword to disambiguate named instance variables and parameters 28 this.year = year; //use "this" keyword to disambiguate named instance variables and parameters 29 } 30 31 //Methods 32 public String toString() { 33 String s = firstName + " " + lastName + ", born " + month + "/" + day + "/" + year; 34 return s; 35 } 36 37 @Override 38 public String firstName() { 39 return firstName; 40 } 41 42 @Override 43 public String lastName() { 44 return lastName; 45 } 46 47 @Override 48 public int month() { 49 return month; 50 } 51 52 @Override 53 public int day() { 54 return day; 55 } 56 57 @Override 58 public int year() { 59 return year; 60 } 61 62 @Override 63 public String initials() { 64 String firstInitial = firstName.substring(0,1); 65 String secondInitial = lastName.substring(0,1); 66 String initials = firstInitial + secondInitial; 67 return initials; 68 } 69 70 @Override 71 public boolean isBoomer() { 72 if (year >= 1946 & year <= 1964) { return true; } //Boomers are born between 1946-1964 73 return false; 74 } 75 } 76