/** * Stores First and Last Name. * Also Has 2 Methods - constructor and toString(). * And four more methods: set() and get() for each data field. * and three more methods: toUpperCase(),toLowerCase(), initials() * * @author William McDaniel Albritton */ public class Name4 implements NameInterface{ /* These Are The Data Fields. Used to STore EACH Object's Data. Syntax: private ClassName variableName; */ private String first; private String last; /** * Constructor - Used To Create EAch Object and Initialize DAta Fields. * * @param firstName is the first name. * @param lastName is the last name. */ public Name4(String firstName, String lastName){ //This Code Initializes The Data Fields. //Syntax: dataField = parameter; first = firstName; last = lastName; } /** * Used to Display The Data Stored In Each Object's Data Field. * * @return a String in format: LastName, FirstName */ public String toString(){ //Create a Local VAriable. String fullName = new String("full name"); //add last name to first name fullName = last + ", " + first; //Return the Local Variable. return fullName; } /** * a method that returns a name in all uppercase letters * * @return a Name with first and last names in uppercase */ public Name4 toUpperCase(){ //Create Local String VAriables and Make all Caps. String firstUpper = first.toUpperCase(); String lastUpper = last.toUpperCase(); //Create Local Name VAriables and Make all Caps. Name4 nameUpper = new Name4(firstUpper, lastUpper); //Return the Local Variable. return nameUpper; } /** * a method that returns a name in all lowercase letters * * @return a Name with first and last names in lowercase */ public Name4 toLowerCase(){ //Create Local String VAriables and Make all lowercase. String firstLower = first.toLowerCase(); String lastLower = last.toLowerCase(); //Create Local Name VAriables and Make all lowercase. Name4 nameLower = new Name4(firstLower, lastLower); //Return the Local Variable. return nameLower; } /** * a method that returns the initials * * @return the initial for a name */ public String initials(){ //Create Local String VAriable for the initials String initial = new String("initials"); initial = first.substring(0, 1)+ ". " + last.substring(0, 1) + ". "; //Return the Local Variable. return initial; } /** * This Is An "Accessor" Method - Used To Get A Data Field. * * @return the First Name */ public String getFirstName(){ //Return the Data Field. return first; } /** * This Is An "Accessor" Method - Used To Get A Data Field. * * @return the Last Name */ public String getLastName(){ //Return the Data Field. return last; } /** * This Is A "Mutator" Method - Used To Set A Data Field. * * @param firstNameParameter is the first name. */ public void setFirstName(String firstNameParameter){ //SEt the Data Field. first = firstNameParameter; } /** * This Is A "Mutator" Method - Used To Set A Data Field. * * @param lastNameParameter is the last name. */ public void setLastName(String lastNameParameter){ //set the Data Field. last = lastNameParameter; } }//End of Class.