Question: Build a class called Account.java. This class should have the following properties: AcctNo, Owner and balance. Also add the appropriate set and get methods, display

Build a class called Account.java. This class should have the following properties: AcctNo, Owner and balance. Also add the appropriate set and get methods, display method and main method. Main() should be used to test this class. In main() instantiate an Account object, fill it with data using the set methods, then call display to display the data. You will also add 2 more methods, deposit(double amt) and withdraw(double amt) methods. Use the main()method to test out this class.

Use the following code, in the main method, to test the Account class?

Account a1;

a1 = new Account(2222, Frank, 1000);

a1.deposit(100.00);

a1.display();

Now in your Account main() method, attempt to withdraw more than the current balance that is available. What happens now?

Use the following code to test the Account class?

Account a1;

a1 = new Account(2222, Frank, 500.00);

a1.deposit(100.00);

a1.withdraw(900.00);

a1.display();

What happened? We will fix this problem in Lab #4 below.

Build an InsufficientFundsException class. Create a new File called InsufficientFunds.java. Have this class extend from the Exception class. Also add to your Account class. Make it so that when the withdraw method attempt to set the balance below zero(the withdraw() method is called, and the amount the user is trying to withdraw is greater than the available balance), the InsufficientFundsException will be thrown. Test your code again, once you have made changes to the Account classs withdraw(double amt) method. What happens????

Lastly, in your Account classs main method, use try-catch blocks to catch this InsufficientFundsException when you call the a1.withdraw(900.00) method.

If you try to withdraw more than the available balance, do you still get a runtime error?????

------------------------------------------------------------------------------------------------------------------------------------------------

public class AccountX throws InsufficientFundsException{ //Properties private int accNo; private String owner; private double balance; //Constructors public AccountX(){ accNo = 0; owner = ""; balance = 0.0; } public AccountX(int acc, String o, double bal){ accNo = acc; owner = o; balance = bal; } //Behaviors public void deposit(double amount){ balance = balance + amount; } public void withdraw (double amount){ balance = balance - amount; } public void setAcc(int acc){ accNo = acc; } public int getAcc(){ return accNo; } public void setOwn(String o){ owner = o; } public String getOwn(){ return owner; } public void setBal(double bal){ balance = bal; } public double getBal(){ return balance; } public void display(){ System.out.println("Account No: " + getAcc()); System.out.println("Owner: " + getOwn()); System.out.println("Balance: $" + getBal()); } public static void main(String[] args){ AccountX a1; a1 = new AccountX(2222,"Frank",1000.00); a1.withdraw(10000); a1.display(); } }

-------------------------------------------------------------------------------------------------------------------------------------------------------------

public class InsufficientFundsException extends TestExceptions{

InsufficientFundsException(double balance){ System.out.println("Insufficient funds.The available balance is: $ "+ balance); }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!