Question
CIST 2372 Java Programming II LAB #2 (35 Points) Error Handling Spring Semester 2018 1.) Build a class called TestExceptions.java. Put the following code in
CIST 2372
Java Programming II
LAB #2 (35 Points)
Error Handling
Spring Semester 2018
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?
2.) 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();
3.) 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 #3.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started