Guest User

PersonAddress.java

a guest
Feb 26th, 2019
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class PersonAddress {
  4. Scanner keyboard = new Scanner(System.in);
  5.  
  6. private String personFirstName;
  7. private String personLastName;
  8. private String personEmail;
  9. private String phoneNumber;
  10.  
  11. public boolean equals(PersonAddress otherObject) // Equals method
  12. {
  13. return (personFirstName.equals(otherObject.getFirstName())) &&
  14. (personLastName.equals(otherObject.getLastName()));
  15. }
  16.  
  17. public void readInput() {
  18.  
  19. System.out.println("What is your first name?");
  20. personFirstName = keyboard.next();
  21. System.out.println("What is your last name?");
  22. personLastName = keyboard.next();
  23.  
  24. System.out.println("What is your email?");
  25. personEmail = keyboard.next();
  26.  
  27. if (personEmail.contains("@")) {
  28.  
  29. if (personEmail.endsWith("@gmail.com") || (personEmail.endsWith("@yahoo.com") || (personEmail.endsWith("@strose.edu")))) {
  30. personEmail = personEmail;
  31.  
  32. } else {
  33. System.out.println("Email does not have correct ending.");
  34. System.out.println("What is your email?");
  35. personEmail = keyboard.next();
  36. }
  37.  
  38. } else {
  39. System.out.println("'@' character not found within email: " + personEmail);
  40. System.out.println("What is your email?");
  41. personEmail = keyboard.next();
  42. }
  43.  
  44.  
  45. System.out.println("What is your phone number?");
  46. phoneNumber = keyboard.next();
  47. if (phoneNumber.length() < 11) {
  48.  
  49. System.out.println("Incorrect phone number format or length. Enter a phone number with hypens.");
  50. phoneNumber = keyboard.next();
  51. }
  52.  
  53. }
  54.  
  55. public void writeOutput() {
  56.  
  57. System.out.println("First name is " + personFirstName);
  58. System.out.println("Last name is " + personLastName);
  59. System.out.println("Email is " + personEmail);
  60. System.out.println("Phone number is " + phoneNumber);
  61.  
  62. }
  63.  
  64. public String getEmail() {
  65. return personEmail;
  66. }
  67.  
  68. public void setEmail(String personEmail) {
  69. if (personEmail.contains("@")) {
  70. if (personEmail.endsWith("@gmail.com") || (personEmail.endsWith("@yahoo.com") || (personEmail.endsWith("@strose.edu")))) {
  71. this.personEmail = personEmail;
  72. } else {
  73. System.out.println("Email does not have correct ending.");
  74. }
  75. }
  76.  
  77. else {
  78. System.out.println("'@' character not found within new email");
  79. }
  80. }
  81.  
  82. public String getFirstName() {
  83. return personFirstName;
  84. }
  85.  
  86. public void setFirstName(String personFirstName) {
  87.  
  88. this.personFirstName = personFirstName;
  89.  
  90. }
  91.  
  92. public String getLastName() {
  93. return personLastName;
  94. }
  95.  
  96. public void setLastName(String personLastName) {
  97.  
  98. this.personLastName = personLastName;
  99.  
  100. }
  101.  
  102. public String getNumber() {
  103. return phoneNumber;
  104. }
  105.  
  106. public void setNumber(String phoneNumber) {
  107.  
  108. if (phoneNumber.indexOf("-") == 3){
  109. this.phoneNumber = phoneNumber;
  110. }
  111. }
  112. }
Add Comment
Please, Sign In to add comment