Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Write a description of class Name here.
- *
- * @author Alex
- * @version 07/01/2010
- */
- public class Name
- {
- private String firstName;
- private String middleName;
- private String lastName;
- public Name()
- {
- firstName = null;
- middleName = null;
- lastName = null;
- }
- //Instance variables
- public Name(String first, String middle, String last)
- {
- firstName = first;
- middleName = middle;
- lastName = last;
- }//end Name
- public String getFirst()
- {
- return firstName;
- }//end getF
- public String getMiddle()
- {
- return middleName;
- }//end getM
- public String getLast()
- {
- return lastName;
- }// end getL
- public String firstMiddleLast()
- {
- return firstName + " " + middleName + " " + lastName;
- }//end FML
- public String lastFristMiddle()
- {
- return lastName + ", " + firstName + " " + middleName;
- }//end LFM
- public boolean equals(Object otherName)
- {
- boolean equal = false;
- if(this.getFirst().equalsIgnoreCase(((Name)otherName).getFirst()))
- if(this.getMiddle().equalsIgnoreCase(((Name)otherName).getMiddle()))
- if(this.getLast().equalsIgnoreCase(((Name)otherName).getLast()))
- {
- equal = true;
- }
- return equal;
- }//end quals
- public String initials(String uFirst, String uMiddle, String uLast)
- {
- uFirst = firstName.toUpperCase();
- uMiddle = middleName.toUpperCase();
- uLast = lastName.toUpperCase();
- return "" + uFirst.charAt(0) + uMiddle.charAt(0) + uLast.charAt(0);
- }// end initials
- public int length()
- {
- return firstName.length() + middleName.length() + lastName.length();
- }
- }
- import java.util.*;
- /**
- *
- * @author Alex
- * @version 08/01/2010
- */
- public class TestName
- {
- public static void main (String[] args)
- {
- //define local variables
- Name name1 = new Name();
- Name name2 = new Name();
- getData(name1);
- System.out.println(name1.firstMiddleLast());
- getData(name2);
- }
- public static void getData(Name otherName)
- {
- String firstName;
- String middleName;
- String lastName;
- Scanner s = new Scanner(System.in);
- //getting input
- System.out.print("Enter the First Name: ");
- firstName = s.nextLine();
- System.out.print("\nEnter the Middle Name: ");
- middleName = s.nextLine();
- System.out.print("\nEnter the Last Name: ");
- lastName = s.nextLine();
- }
- }
Add Comment
Please, Sign In to add comment