The problem I have is, say I am storing the phone number and don't want their phone number to contain any characters, have a length of 10 numbers and start with 1 and return "Not Valid" if one of these occur. I have tried to create if statements in the setter but it is not returning the "Not Valid". This is what I have so far import java.util.Scanner; class Clint { private String id; private String name; private long prson; private Address home; public Clint() { prson = 0; } public Clint(String acc, String nameGiven, long bal, Address residence) { id = acc; name = nameGiven; prson = bal; home = residence; } Scanner sc = new Scanner(System.in); // deposit money into the bank account by given amount amt public void deposit(long amt) { prson += amt; } // if amount is not given ask the user for the amount public void deposit() { System.out.print("Enter Amount(to deposit): $"); long amt = sc.nextLong(); prson += amt; } // withdraw money from the bank account public void withdraw(long amt) { if (prson >= amt) { prson -= amt; } else { System.out.println("Insufficient funds!"); } } // if amt is not given ask the user for the amount public void withdraw() { System.out.print("Enter Amount(to withdraw): $"); long amt = sc.nextLong(); if (prson >= amt) { prson -= amt; } else { System.out.println("Insufficient funds!"); } } // getters and setters for all the private members public String getAccNumber() { return id; } public String getHolderName() { return name; } public long getBalance() { return prson; } public void setBalance(long amt) { prson = amt; } public void setHolderName(String n) { name = n; } public void setAccNumber(String acc) { id = acc; } public void setPhoneNumber(String phoneNumber) { if (phoneNumber.matches("[a-zA-z]+)")) { phoneNumber = "Not Valid"; } else if (phoneNumber.length() > 10) { phoneNumber = "Not Valid"; } else if (phoneNumber.startsWith("1")){ phoneNumber = "Not Valid"; } } // method to display account details public void printDetails() { System.out.println("[" + id + "-" + name + ": $" + prson +home.toString()+ "]"); } } public class Address { private String phoneNumber; // The city in which the address is located private String city; // The state in which the address is located private String street; public Address(String number,String road, String town ) { phoneNumber= number; city = town; street = road; } public String getPhoneNumber() { return phoneNumber; } // public void setPhoneNumber(String phoneNumber) { // if (phoneNumber.matches("[a-zA-z]+)")) { // phoneNumber = "Not Valid"; // } // else if (phoneNumber.length() > 10) { // phoneNumber = "Not Valid"; // } // // else if (phoneNumber.startsWith("1")){ // phoneNumber = "Not Valid"; // } // else { // this.phoneNumber = phoneNumber; // } // } public String getCity() { return city; } public void setCity(String name) { this.city = city; } public String getstreet() { return street; } public void setStreet(String Street) { this.street = Street; } /** The toString method @return Information about the address. */ public String toString() { return " Name: " + phoneNumber + city + "\n treet " + phoneNumber; } }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

The problem I have is, say I am storing the phone number and don't want their phone number to contain any characters, have a length of 10 numbers and start with 1 and return "Not Valid" if one of these occur.

I have tried to create if statements in the setter but it is not returning the "Not Valid". This is what I have so far

import java.util.Scanner;
class Clint {

 
    
    private String id;
    private String name;
    private long prson;
    private Address home;


    public Clint() {
        prson = 0;
    }

    public Clint(String acc, String nameGiven, long bal, Address residence) {
        id = acc;
      name = nameGiven;
        prson = bal;
        home = residence;
    }

    Scanner sc = new Scanner(System.in);

    // deposit money into the bank account by given amount amt
    public void deposit(long amt) {
        prson += amt;
    }

    // if amount is not given ask the user for the amount
    public void deposit() {
        System.out.print("Enter Amount(to deposit): $");
        long amt = sc.nextLong();
       prson += amt;
    }

    // withdraw money from the bank account
    public void withdraw(long amt) {
        if (prson >= amt) {
            prson -= amt;
        } else {
            System.out.println("Insufficient funds!");
        }
    }

    // if amt is not given ask the user for the amount
    public void withdraw() {
        System.out.print("Enter Amount(to withdraw): $");
        long amt = sc.nextLong();
        if (prson >= amt) {
            prson -= amt;
        } else {
            System.out.println("Insufficient funds!");
        }
    }

    // getters and setters for all the private members
    public String getAccNumber() {
        return id;
    }
     


    public String getHolderName() {
        return name;
    }

    public long getBalance() {
        return prson;
    }

    public void setBalance(long amt) {
        prson = amt;
    }

    public void setHolderName(String n) {
        name = n;
    }

    public void setAccNumber(String acc) {
        id = acc;
    }
    public void setPhoneNumber(String phoneNumber) {
        if (phoneNumber.matches("[a-zA-z]+)")) {
           phoneNumber = "Not Valid";
        } 
        else if (phoneNumber.length() > 10) {
            phoneNumber = "Not Valid";
        }

        else if (phoneNumber.startsWith("1")){
            phoneNumber = "Not Valid";
        }
       
    }

    // method to display account details
    public void printDetails() {
        System.out.println("[" + id + "-" + name + ": $" + prson +home.toString()+ "]");
    }
    
    
    }

 


public class Address {
    private String phoneNumber;

   // The city in which the address is located
   private String city;

   // The state in which the address is located
   private String street;

   

   

   public Address(String number,String road, String town )
   {
     phoneNumber= number;
      city = town;
      street = road;
      
   }
       public String getPhoneNumber() {
        return phoneNumber;
    }

//    public void setPhoneNumber(String phoneNumber) {
//        if (phoneNumber.matches("[a-zA-z]+)")) {
//            phoneNumber = "Not Valid";
//        } 
//        else if (phoneNumber.length() > 10) {
//            phoneNumber = "Not Valid";
//        }
//
//        else if (phoneNumber.startsWith("1")){
//            phoneNumber = "Not Valid";
//        }
//        else {
//        this.phoneNumber = phoneNumber;
//        }
//    }
    
      
      
    public String getCity() {
        return city;
    }

    public void setCity(String name) {
        this.city = city;
    }

    public String getstreet() {
        return street;
    }

    public void setStreet(String Street) {
        this.street = Street;
    }

   
   /**
      The toString method
      @return Information about the address.
   */

    public String toString() {
        return " Name: " + phoneNumber  + city + "\n treet " + phoneNumber;

      

    
  
   }
}
    

 

Expert Solution
steps

Step by step

Solved in 3 steps with 4 images

Blurred answer
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY