Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public class BankCustomer { private int acctNumber; private double balance; private String name; /** * C'tor method * @param acctNumber * @param balance * @param

public class BankCustomer {

private int acctNumber; private double balance; private String name;

/** * C'tor method * @param acctNumber * @param balance * @param name * @throws BCException */

public BankCustomer(int acctNumber, double balance, String name) throws Exception{ // a constructor to initialize objects that will be used in the code this.setAcctNumber(acctNumber); this.setBalance(balance); this.setName(name); } public BankCustomer(){ // create 3 instance variables named as acctNumber, balance and name this.acctNumber = 10001; this.balance = 120.0; this.name = "sample"; } // Start with acctNumber make sure that it will handle errors and gives exception when user type a wrong input public void setAcctNumber(int acctNumber) throws Exception { // private int acctNumber; ranges between 10001 and 99999 if (acctNumber >= 10001 && acctNumber <= 99999){ this.acctNumber = acctNumber; } else{ Exception me = new Exception(); me.setMessage("The account number passed " + acctNumber + " is not valid"); throw (me); } } // Do the balance next, provide a code that will also give an exception once the user gives a wrong input public void setBalance(double balance) throws Exception { // private double balance; must be at least 100 if (balance >= 100){ this.balance = balance; } else { BCException me = new BCException(); me.setMessage("The amount added " + balance + " should be more than 100"); throw (me); } } // Last is the name variable, do the same code above which handle errors public void setName(String name) throws Exception { // private String name; must be at least 5 non-blank characters long if (name.trim().length() >= 5){ this.name = name.trim(); } else { BCException me = new BCException(); me.setMessage("The name " + name + " should be atleast 5 non-blank characters"); throw (me); } } // get method for the instance variable declared above public int getAcctNumber() { return acctNumber; }

public double getBalance() { return balance; }

public String getName() { return name; } }

Please help me fix my code I'm not even sure how to fix it and can you please add a tostring and in line comments for every step so I understand each step of the code thank you.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions