Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class PersonAddress {
- Scanner keyboard = new Scanner(System.in);
- private String personFirstName;
- private String personLastName;
- private String personEmail;
- private String phoneNumber;
- public boolean equals(PersonAddress otherObject) // Equals method
- {
- return (personFirstName.equals(otherObject.getFirstName())) &&
- (personLastName.equals(otherObject.getLastName()));
- }
- public void readInput() {
- System.out.println("What is your first name?");
- personFirstName = keyboard.next();
- System.out.println("What is your last name?");
- personLastName = keyboard.next();
- System.out.println("What is your email?");
- personEmail = keyboard.next();
- if (personEmail.contains("@")) {
- if (personEmail.endsWith("@gmail.com") || (personEmail.endsWith("@yahoo.com") || (personEmail.endsWith("@strose.edu")))) {
- personEmail = personEmail;
- } else {
- System.out.println("Email does not have correct ending.");
- System.out.println("What is your email?");
- personEmail = keyboard.next();
- }
- } else {
- System.out.println("'@' character not found within email: " + personEmail);
- System.out.println("What is your email?");
- personEmail = keyboard.next();
- }
- System.out.println("What is your phone number?");
- phoneNumber = keyboard.next();
- if (phoneNumber.length() < 11) {
- System.out.println("Incorrect phone number format or length. Enter a phone number with hypens.");
- phoneNumber = keyboard.next();
- }
- }
- public void writeOutput() {
- System.out.println("First name is " + personFirstName);
- System.out.println("Last name is " + personLastName);
- System.out.println("Email is " + personEmail);
- System.out.println("Phone number is " + phoneNumber);
- }
- public String getEmail() {
- return personEmail;
- }
- public void setEmail(String personEmail) {
- if (personEmail.contains("@")) {
- if (personEmail.endsWith("@gmail.com") || (personEmail.endsWith("@yahoo.com") || (personEmail.endsWith("@strose.edu")))) {
- this.personEmail = personEmail;
- } else {
- System.out.println("Email does not have correct ending.");
- }
- }
- else {
- System.out.println("'@' character not found within new email");
- }
- }
- public String getFirstName() {
- return personFirstName;
- }
- public void setFirstName(String personFirstName) {
- this.personFirstName = personFirstName;
- }
- public String getLastName() {
- return personLastName;
- }
- public void setLastName(String personLastName) {
- this.personLastName = personLastName;
- }
- public String getNumber() {
- return phoneNumber;
- }
- public void setNumber(String phoneNumber) {
- if (phoneNumber.indexOf("-") == 3){
- this.phoneNumber = phoneNumber;
- }
- }
- }
Add Comment
Please, Sign In to add comment