[go: up one dir, main page]

0% found this document useful (0 votes)
403 views2 pages

Opps Task

1. Create a Person class and Account class with associations as shown in the class diagram. 2. Create accounts for "smith" and "Kathy" with initial balances, deposit to smith's account, and withdraw from Kathy's account, displaying the updated balances. 3. Extend the Account class to SavingsAccount and CurrentAccount classes, overriding the withdraw method to check minimum balances or overdraft limits.

Uploaded by

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

Opps Task

1. Create a Person class and Account class with associations as shown in the class diagram. 2. Create accounts for "smith" and "Kathy" with initial balances, deposit to smith's account, and withdraw from Kathy's account, displaying the updated balances. 3. Extend the Account class to SavingsAccount and CurrentAccount classes, overriding the withdraw method to check minimum balances or overdraft limits.

Uploaded by

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

Lab 1: Inheritance and Polymorphism

-------------------------Optional-----------------------------------------------------------------------
Exercise1: Create Person and Account Class as shown below in class diagram. Ensure minimum
balance of INR 500 in a bank account is available.

Figure 1: Association of person with account class

a) Create Account for smith with initial balance as INR 2000 and for Kathy with initial balance as
3000.(accNum should be auto generated).
b) Deposit 2000 INR to smith account.
c) Withdraw 2000 INR from Kathy account.
d) Display updated balances in both the account.
e) Extend the functionality through Inheritance and polymorphism. Inherit two classes Savings
Account and Current Account from account class. And Implement the following in the respective
classes.

- Savings Account
a. Add a variable called minimum Balance and assign final modifier.
b. Override method called withdraw (This method should check for minimum balance and allow
withdraw to happen)

- Current Account
a. Add a variable called overdraft Limit
b. Override method called withdraw (checks whether overdraft limit is reached and returns a
Boolean value accordingly)

-------------------------------Mandatory------------------------------------------------------------------------

Exercise 3: Using an inheritance hierarchy, design a Java program to model items at a library
(books, journal articles, videos and CDs.) Have an abstract superclass called Item and include
common information that the library must have for every item (such as unique identification number,
title, and number of copies). No actual objects of type Item will be created - each actual item will be an
object of a (non-abstract) subclass. Place item-type-specific behavior in subclasses (such as a video's
year of release, a CD's musical genre, or a book's author).
More in detail:
1. Implement an abstract superclass called Item and define all common operations on this
class (constructors, getters, setters, equals, toString, print, checkIn, checkOut, addItem, etc).
Have private data for: identification number, title, and number of copies.
2. Implement an abstract subclass of Item named WrittenItem and define all common
operations on this class. Added private data for author.
3. Implement 2 subclasses of WrittenItem: Book and JournalPaper.

3.1. Class Book: no new private data. When needed, override/overload methods from
the superclass.
3.2. Class JournalPaper: added private data for year published. When needed,
override/overload methods from the superclass.

4. Implement another abstract subclass of Item named MediaItem and define all common
operations on this class. Added private data for runtime (integer).
5. Implement 2 subclasses of MediaItem: Video and CD.
5.1. Class Video: added private data for director, genre and year released. When
needed, override/overload methods from the superclass.
5.2. Class CD: added private data for artist and genre. When needed,
override/overload methods from the superclass.
Write the definitions of these classes and a client program (your choice!) showing them in use.

You might also like