Guest User

Untitled

a guest
Jul 22nd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1.  
  2. /**
  3. * Write a description of class Name here.
  4. *
  5. * @author Alex
  6. * @version 07/01/2010
  7. */
  8. public class Name
  9. {
  10.  
  11. private String firstName;
  12. private String middleName;
  13. private String lastName;
  14.  
  15. public Name()
  16. {
  17. firstName = null;
  18. middleName = null;
  19. lastName = null;
  20. }
  21. //Instance variables
  22.  
  23.  
  24.  
  25. public Name(String first, String middle, String last)
  26. {
  27. firstName = first;
  28. middleName = middle;
  29. lastName = last;
  30. }//end Name
  31.  
  32.  
  33.  
  34. public String getFirst()
  35. {
  36. return firstName;
  37.  
  38. }//end getF
  39.  
  40. public String getMiddle()
  41. {
  42. return middleName;
  43.  
  44. }//end getM
  45.  
  46. public String getLast()
  47. {
  48. return lastName;
  49.  
  50. }// end getL
  51.  
  52. public String firstMiddleLast()
  53. {
  54. return firstName + " " + middleName + " " + lastName;
  55.  
  56. }//end FML
  57.  
  58. public String lastFristMiddle()
  59. {
  60. return lastName + ", " + firstName + " " + middleName;
  61.  
  62. }//end LFM
  63.  
  64. public boolean equals(Object otherName)
  65. {
  66. boolean equal = false;
  67.  
  68. if(this.getFirst().equalsIgnoreCase(((Name)otherName).getFirst()))
  69. if(this.getMiddle().equalsIgnoreCase(((Name)otherName).getMiddle()))
  70. if(this.getLast().equalsIgnoreCase(((Name)otherName).getLast()))
  71. {
  72. equal = true;
  73. }
  74. return equal;
  75. }//end quals
  76.  
  77. public String initials(String uFirst, String uMiddle, String uLast)
  78. {
  79. uFirst = firstName.toUpperCase();
  80. uMiddle = middleName.toUpperCase();
  81. uLast = lastName.toUpperCase();
  82. return "" + uFirst.charAt(0) + uMiddle.charAt(0) + uLast.charAt(0);
  83.  
  84. }// end initials
  85.  
  86. public int length()
  87. {
  88. return firstName.length() + middleName.length() + lastName.length();
  89.  
  90. }
  91. }
  92.  
  93.  
  94.  
  95. import java.util.*;
  96. /**
  97. *
  98. * @author Alex
  99. * @version 08/01/2010
  100. */
  101. public class TestName
  102. {
  103.  
  104.  
  105. public static void main (String[] args)
  106. {
  107. //define local variables
  108. Name name1 = new Name();
  109. Name name2 = new Name();
  110. getData(name1);
  111. System.out.println(name1.firstMiddleLast());
  112.  
  113. getData(name2);
  114. }
  115.  
  116. public static void getData(Name otherName)
  117. {
  118. String firstName;
  119. String middleName;
  120. String lastName;
  121. Scanner s = new Scanner(System.in);
  122. //getting input
  123. System.out.print("Enter the First Name: ");
  124. firstName = s.nextLine();
  125. System.out.print("\nEnter the Middle Name: ");
  126. middleName = s.nextLine();
  127. System.out.print("\nEnter the Last Name: ");
  128. lastName = s.nextLine();
  129.  
  130. }
  131. }
Add Comment
Please, Sign In to add comment