13 Assignment 3

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

1

Assignment-3: Object Oriented Programming Lab (Code: PCC-CS593) (Abstract class, interface & package)

1. Create an abstract class Account as shown below:


a. Data members:
i. accountNumber
ii. accountHolderName
iii. address
iv. balance
b. Methods:
i. withdraw()- abstract
ii. deposite()- abstract
iii. display() to show the balance of the account.
Create a subclass of Account named SavingsAccount that has the following details:
a. Data members:
i. rateOfInterest
b. Methods:
i. calculateAmount() to calculate the total balance after calculating interest.
ii. display() to display rate of interest with new balance and full account holder
details.
Create another subclass of Account named CurrentAccount that has the following details:
a. Data members:
i. overdraftLimit
b. Methods:
i. display() to show overdraft limit along with the full account holder details.
Create objects of these two classes and call their methods. Use appropriate constructors.

2. Create an abstract class Person. Define two subclasses Employee and Worker from it. Use
proper method to accept and display the details for the same. The fields of Employee are
empNo, empName, address. Similar fields for Worker are name and workingHours.

3. Write an interface called Numbers with a method int process(int x, int y). Write
a class called Sum, in which the method process() finds the sum of two numbers and returns
an integer value. Write another class called Average, in which the process() method finds
the average of the two numbers and returns an integer value.

4. Write an interface Examination with a method pass(int marks) that returns a boolean
value. Write another interface called Classify with a method division(int average)
which returns a String. Write a class Result which implements both Examination and
Classify. The pass() method should return true if the marks is greater than or equal to 50
else false. The method division() should return "First" when the parameter average is 60
or more, "Second" when the average is 50 or more but less than 60, "No Division" when
average is less than 50.

5. Create an interface Shape. Derive three classes Sphere, Cone and Cylinder from it.
Calculate area and volume of all (using method overriding).

6. Design an interface named Stack with the following methods:


a. To push elements into the stack.
b. To pop elements from the stack.
c. To check whether the stack is empty or not.
2

Implement the stack with the help of array and if the size of the array becomes too small to hold
the elements, create a new one. Test this interface by inheriting it in its subclass
StackTest.java.
7. Design an interface named Queue with the following methods:
a. To add elements into the queue.
b. To remove elements from the queue.
c. To check whether the stack is empty or not.
Implement the queue with the help of array and if the size of the array becomes too small to hold
the elements, create a new one. Test this interface by inheriting it in its subclass
QueueTest.java.

8. Design an interface with a method reversal. This method takes a String as its input and returns
the reversed String. Create a class StringReversal that implements the method [do not
use predefined methods].

9. Write a program to create a package named pack and store Addition class in it. Now create
another class TestPackage containing main() method and use an object of Addition
class in the main() method. Place TestPackage class in the default package or in the
pack package. In both cases run the program TestPackage without using an IDE.

10. Create a class FactorialIterative which defines a method for finding out the factorial of
a given number in iteratively. Create another class FactorialRecursive which defines a
method for finding out the factorial of a given number in recursively. Place the
FactorialIterative class in "iterative" package and the FactorialRecursive
class in "recursive" package. Create a class TestFactorial containing main() method
in "default" package which uses both classes (i.e. FactorialIterative and
FactorialRecursive) to find out the factorial of a number. Compile and run this
program without using an IDE.

You might also like