Advertisement
Guest User

PersonAddress.java

a guest
Feb 25th, 2019
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.08 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class PersonAddress
  4. {
  5. Scanner keyboard = new Scanner(System.in);
  6.  
  7.  
  8. private String personFirstName;
  9. private String personLastName;
  10. private String personEmail;
  11. private String phoneNumber;
  12.  
  13. public boolean equals (PersonAddress otherObject) // Equals method
  14. {
  15. return (personFirstName.equalsIgnoreCase (otherObject.getFirstName())) &&
  16. (personLastName == otherObject.getLastName());
  17.  
  18. }
  19.  
  20. public void readInput(){
  21.  
  22. System.out.println("What is your first name?");
  23. personFirstName = keyboard.next();
  24. System.out.println("What is your last name?");
  25. personLastName = keyboard.next();
  26.  
  27. System.out.println("What is your email?");
  28. personEmail = keyboard.next();
  29.  
  30. if (personEmail.contains("@")){
  31.  
  32. if (personEmail.endsWith("@gmail.com") || (personEmail.endsWith("@yahoo.com") || (personEmail.endsWith("@strose.edu")))){
  33. personEmail = personEmail;
  34.  
  35. }
  36.  
  37. else{
  38. System.out.println("Email does not have correct ending.");
  39. System.out.println("What is your email?");
  40. personEmail = keyboard.next();
  41. }
  42.  
  43. }
  44.  
  45. else{
  46. System.out.println("'@' character not found within email: " + personEmail);
  47. System.out.println("What is your email?");
  48. personEmail = keyboard.next();
  49. }
  50.  
  51.  
  52. System.out.println("What is your phone number?");
  53. phoneNumber = keyboard.next();
  54. if (phoneNumber.length() < 11){
  55.  
  56. System.out.println("Incorrect phone number format or length. Enter a phone number with hypens.");
  57. phoneNumber = keyboard.next();
  58.  
  59. }
  60. String firstSubNumber = phoneNumber.substring(4);
  61.  
  62. if (phoneNumber.indexOf("-") == 3){
  63.  
  64.  
  65. }
  66.  
  67. System.out.println(firstSubNumber);
  68.  
  69.  
  70.  
  71.  
  72. }
  73.  
  74. public void writeOutput()
  75. {
  76.  
  77. System.out.println("First name is " + personFirstName);
  78. System.out.println("Last name is " + personLastName);
  79. System.out.println("Email is " +personEmail);
  80. System.out.println("Phone number is "+phoneNumber);
  81.  
  82. }
  83.  
  84. public String getEmail()
  85. {
  86. return personEmail;
  87. }
  88.  
  89. public void setEmail(boolean askChangeEmail)
  90. {
  91. String newEmail = " ";
  92. String askSetEmail = "no";
  93. askSetEmail = keyboard.nextLine().toLowerCase();
  94. if (askSetEmail.equals("yes")){
  95. System.out.println("What email?");
  96. newEmail = keyboard.nextLine();
  97. if (newEmail.contains("@")){
  98.  
  99. if (newEmail.endsWith("@gmail.com") || (newEmail.endsWith("@yahoo.com") || (newEmail.endsWith("@strose.edu")))){
  100. this.personEmail = newEmail;
  101. writeOutput();
  102. }
  103.  
  104. else{
  105. System.out.println("Email does not have correct ending.");
  106. }
  107.  
  108. }
  109.  
  110. else{
  111. System.out.println("'@' character not found within new email");
  112. }
  113.  
  114. }
  115.  
  116.  
  117. }
  118.  
  119. public String getFirstName()
  120. {
  121. return personFirstName;
  122. }
  123.  
  124. public void setFirstName(String personFirstName)
  125. {
  126.  
  127. this.personFirstName = personFirstName;
  128.  
  129. }
  130.  
  131. public String getLastName()
  132. {
  133. return personLastName;
  134. }
  135.  
  136. public void setLastName(String personLastName)
  137. {
  138.  
  139. this.personLastName = personLastName;
  140.  
  141. }
  142.  
  143. public String getNumber()
  144. {
  145. return phoneNumber;
  146. }
  147.  
  148. public void setNumber(boolean askChangeNumber)
  149. {
  150.  
  151. String newNumber = "";
  152. String askSetNumber = "no";
  153. askSetNumber = keyboard.nextLine().toLowerCase();
  154. if (askSetNumber.equals("yes")){
  155.  
  156. System.out.println("Number?");
  157. newNumber = keyboard.nextLine();
  158. System.out.println(newNumber);
  159.  
  160.  
  161. }
  162.  
  163.  
  164.  
  165.  
  166. }
  167.  
  168. public boolean askChangeEmail(){
  169. System.out.println("Do you want to change your email (Yes/No)?");
  170. String changeEmail = keyboard.nextLine().toLowerCase();
  171. if (changeEmail.equals("yes")){
  172. return true;
  173. }
  174. else{
  175. return false;
  176. }
  177.  
  178. }
  179.  
  180. public boolean askChangeNumber(){
  181.  
  182. System.out.println("Do you want to change your phone number? (Yes/No)");
  183. String changeNumber = keyboard.nextLine().toLowerCase();
  184. if (changeNumber.equals("yes")){
  185. return true;
  186. }
  187. else{
  188. return false;
  189. }
  190.  
  191. }
  192.  
  193. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement