0% found this document useful (0 votes)
44 views3 pages

Practical 7

Uploaded by

Chavini Hewage
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views3 pages

Practical 7

Uploaded by

Chavini Hewage
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

BSc (Hons) in Information Technology

Year 2
Lab Exercise 7

IT2030 – Object Oriented Programming Semester 1, 2020

Objectives:

Write Programs that make uses of Exception Handling

Compulsory
Exercise 1

1) Consider the following BankDemo Application to perform deposit and withdraw amount from the
customer account. To perform these operations, you should create an Account class and validate
the withdrawal amount lest make the account overdue. You should create custom exception class
“InsufficientBalanceException”.
The sample BankDemo Application main program is given below with sample output. Your
implementation should satisfy the same.

When you withdraw more than the existing account throw InsufficientBalanceException. When
you run the program out put should be as follows.

1
BSc (Hons) in Information Technology
Year 2
Lab Exercise 7

IT2030 – Object Oriented Programming Semester 1, 2020

a) Create InsufficientBalanceException class and amount should be able to pass through the
constructor of this custom exception class

b) Create Account class that holds balance and Account No. Implement operations to display
existing balance, account number and account number can be assigned through the
Constructor

c) Implement the deposit operation and that increases the existing balance in the account

d) Implement the withdraw operation and that reduces the balance with given value. In case if
balance is not sufficient throw InsufficientBalanceException in the method and you should
handle it in the BankDemo Application. You throw this in the withdraw operation as below
throw new InsufficientBalanceException(amount);

Exercise 2

2) Refer the Question 1) and Modify the above BankDemo class to give the below output

(No need to consider the keyboard input validations in your implementation)

2
BSc (Hons) in Information Technology
Year 2
Lab Exercise 7

IT2030 – Object Oriented Programming Semester 1, 2020

a) In the modified program user should enter the withdrawal amount as keyboard input and this
activity should continue as infinite loop until user response for the question “Do you wish to
continue ?” If user answers as “no” program will terminate

b) You should extend the above exception handling with including finally block. In the finally
block you should ask the above question “Do you wish to continue?”

c) If user response “yes” for the above question a) in your program should deposit the same
amount for the account and continue the withdrawal process

d) Make sure you should not duplicate the logics in the program for above modification (Consider
OOP concepts)

You might also like