Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Build a class called TestExceptions.java. Put the following code in the main method. int myArr = new int[10]; int x,y,z; x=0; y=10; z=y/x; myArr[10] =

  1. Build a class called TestExceptions.java. Put the following code in the main method.

int myArr = new int[10];

int x,y,z;

x=0;

y=10;

z=y/x;

myArr[10] = 0;

Compile and run this class. What happens?

Now add try/catch blocks to catch these exceptions?

Is there another way that you can prevent a run-time error without using try-catch blocks?

  1. Next build an Account class. The Account class should have 3 Properties: Balance, Owner and AcctNo. The Account class should have 2 constructors, one that takes all 3 properties and one that takes no args(the default). The Account class should have set and get methods as well as deposit and withdraw methods. Also include a display() method that outputs AcctNo, Owner and Balance. Use a 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();

  1. 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();

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

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2014 Integration Services

Authors: Brian Knight, Devin Knight

1st Edition

1118850904, 9781118850909

More Books

Students also viewed these Databases questions

Question

=+associated with political parties and if so, which ones? Are

Answered: 1 week ago