Advertisement
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.equalsIgnoreCase (otherObject.getFirstName())) &&
- (personLastName == 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();
- }
- String firstSubNumber = phoneNumber.substring(4);
- if (phoneNumber.indexOf("-") == 3){
- }
- System.out.println(firstSubNumber);
- }
- 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(boolean askChangeEmail)
- {
- String newEmail = " ";
- String askSetEmail = "no";
- askSetEmail = keyboard.nextLine().toLowerCase();
- if (askSetEmail.equals("yes")){
- System.out.println("What email?");
- newEmail = keyboard.nextLine();
- if (newEmail.contains("@")){
- if (newEmail.endsWith("@gmail.com") || (newEmail.endsWith("@yahoo.com") || (newEmail.endsWith("@strose.edu")))){
- this.personEmail = newEmail;
- writeOutput();
- }
- 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(boolean askChangeNumber)
- {
- String newNumber = "";
- String askSetNumber = "no";
- askSetNumber = keyboard.nextLine().toLowerCase();
- if (askSetNumber.equals("yes")){
- System.out.println("Number?");
- newNumber = keyboard.nextLine();
- System.out.println(newNumber);
- }
- }
- public boolean askChangeEmail(){
- System.out.println("Do you want to change your email (Yes/No)?");
- String changeEmail = keyboard.nextLine().toLowerCase();
- if (changeEmail.equals("yes")){
- return true;
- }
- else{
- return false;
- }
- }
- public boolean askChangeNumber(){
- System.out.println("Do you want to change your phone number? (Yes/No)");
- String changeNumber = keyboard.nextLine().toLowerCase();
- if (changeNumber.equals("yes")){
- return true;
- }
- else{
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement