/** * A class that stores first, middle and last name and has several methods * * @author William McDaniel Albritton */ public class ThreeNames extends Name5{ //data fields //last and first are inherited from class Name5 private String middle; /** * Constructor * * @param aFirst is the first name * @param aMiddle is the middle name * @param aLast is the last name */ public ThreeNames(String aFirst, String aMiddle, String aLast){ //must first called the superclass's constructor when using inheritance //"super" is the constructor for the superclass (class Name5) //public Name5(String firstName, String lastName) super(aFirst, aLast); middle = aMiddle; } /** * Automatically called by println() or print() method! * * @return a String in "first last" format */ public String toString(){ //Create a Local VAriable. String fullName = new String("full name"); //add last name to first name fullName = last + ", " + first + " " + middle; //Return the Local Variable. return fullName; } /** * Accessor method * * @return a middle name */ public String getMiddleName(){ return middle; } /** * Mutator method * * @param theMiddle is the middle name */ public void setMiddleName(String theMiddle){ middle = theMiddle; } /** * Makes All The Data Fields UpperCase. * OVERRIDES (replaces) Name's toUpperCase() method. * * @return a Name with first, middle, and last names in lowercase */ public ThreeNames toUpperCase(){ //Create Local String VAriables and Make all Caps. String firstUpper = first.toUpperCase(); String lastUpper = last.toUpperCase(); String middleUpper = middle.toUpperCase(); //Create Local Name VAriables and Make all Caps. ThreeNames nameUpper = new ThreeNames(firstUpper, middleUpper, lastUpper); //Return the Local Variable. return nameUpper; } /** * Makes All The Data Fields LowerCase (Override). * OVERRIDES (replaces) Name's toLowerCase() method. * * @return a Name with first and last names in lowercase */ public ThreeNames toLowerCase(){ //Use Name5's toLowerCase() method to Do MOst of The Work. Name5 nameLower = super.toLowerCase(); //Create Lowercase for All 3 Names String firstLower = nameLower.getFirstName(); String lastLower = nameLower.getLastName(); String middleLower = middle.toLowerCase(); //Create Local Name VAriables and Make all lowercase. ThreeNames threeNamesLower = new ThreeNames(firstLower, middleLower, lastLower); //Return the Local Variable. return threeNamesLower; } /** * Used to Display The Initials. * * @return The Initials For Someone's Name. */ public String initials(){ //Create a Local VAriable For Initials. String myInitials = first.substring(0, 1) + ". " + middle.substring(0, 1) + ". " + last.substring(0, 1) + "."; return myInitials; } /* NOTE: Methods getFirstName, getLastName, setFirstName, setLastName are inherited from the superclass (class Name5), so we do NOT need to rewrite them in the subclass */ }//end of class