Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Assignment on Inheritance,Abstract class and Interface

Q1.Define a class Employee having basic data members empName, empID and empSal, with
constructors and necessary member functions. Define a class Manager which is inherited
from Employee class and having a data member bonus. Define the driver class that create
object of the class Manager and access Manager details.

Q2. We need to develop a model of students and teachers in an application. We can define a
super class called Person to store common properties such as name and address. Define a
sub-classes Student and Teacher for their specific properties. For Students, we need to
maintain the courses taken and their respective grades; add a course with grade, print all
courses taken and the average grade.

Assume that.
1. A student can take maximum 6 courses for the entire program.
2. For teachers, we need to maintain the courses taught currently, and able to add or remove a
course taught.
3. A teacher can teaches maximum 5 courses concurrently.

Test the methods of both the derived classes by creating objects of the derived classes in the
main method of another class.
Q3. Define an abstract class named as Shape, having data members dimOne and dimTwo.
Extend this class to create two concrete classes named as Rectangle and Triangle. Override
the computeArea() method in the sub classes. Invoke the computeArea() method in the main
method of another Driver class through an abstract class reference variable.

Q4. Define a class named Shape, having the member function draw() and erase() that prints
“Drawing Shape” and “Erasing Shape” respectively.

Define three sub classes, Circle, Triangle and Square and all the derived classes should
override the parent class functions - draw () and erase (). The draw() method should print
“Drawing Circle”, “Drawing Triangle” and “Drawing Square” respectively. The erase()
method should print “Erasing Circle”, “Erasing Triangle” and “Erasing Square” respectively.
Create the objects of Circle, Triangle and Square, assign each to Shape variable(reference)
and call draw() and erase() method using each object.
Q5. Define an interface Calculator which has the basic methods add(), sub( ), mul() and div().
Define a concrete class named as DemoCalculator that implements the interface. Define the
driver class, which create object reference of the interface Calculator and perform all basic
operation of the calculator.
Q6. Define an Interface ScientificCalculator, which is extended from the interface
Calculator(Q.5 ). Define the driver class, which create object reference of the interface
Calculator and perform all basic operation of the calculator and ScientificCalculator.

Mini Project
Title: Develop Banking Application
Requirement:
BankAccount.java is the Super Class for Savings Account. This program was created to
develop OOP skills, in particular - Inheritance and Abstraction. BankAccount.java has a
deposit, withdrawal, addInterest, and monthlyTotalAmount methods. It also has the
setter/mutator method: setMonthlyFee, and the getter/accessor methods: getBalance,
getNumberOfDeposits, getNumberOfWithdrawals, getInterestRate, and getMonthlyFee.
BankAccount.java is an abstract class with the abstract methods withdraw, deposit, and
monthlyTotal.
Abstract classes can't be instantiated and BankAccount serves as a Superclass for the
SavingsAccount Subclass. The SavingsAccount Subclass defines the above abstract methods
and extends (inherits) the other propeties and methods from BankAccount.
SavingsAccountDemo.java provides a demo sample of how to utilise the bank program that
has been created. In this file, a new object mySavingsAcc is created from its constructor. This
takes the value $10,000, 3% Annual Interest, and a $4 monthly fee. This will be the amount in
the bank, the interest rate, and fees we will be working with.
If more than 4 withdrawals are made per month the fee will be increased by $1 per additional
transaction. The program asks the user for withdrawals and deposits and displays the total
amount in the bank account. It also outputs the number of deposits and withdrawals made.
WARNING: monthlyTotal() calls super.monthlyTotalAmount(). This Subtracts monthly fee,
adds interest. Resets monthly deposits and withdrawals to 0.
Ensure that the monthlyTotal() is called after the deposits and withdrawls number has been
output else it will be reset to 0.
The program calculates the balance at the end of the month taking into consideration all
deposits, withdrawals, fees, and interest.

The following link can be used for your reference(Do not copy the code, write your own
code).
https://github.com/Jon-Peppinck/javaBankInheritAbstract

Pradipta Kumar Pattanayak


Department of Computer Science
Silicon Institute of Technology
ppattanayak@silicon.ac.in

You might also like