Sunteți pe pagina 1din 2

OOP Exercise Set 3

INHERITENCE

1. Assume that a bank maintains 2 kinds of accounts for its customers, one called
savings account & the other current account. The savings account provides
compound interest & withdrawal facilities but no cheque book facility. The
current account provides cheque book facility but no interest. Current account
holders should maintain a minimum balance & if the balance falls below this
level, a service charge is imposed.
Create a class Account that store customer name, account number, and type of
account. From this derive the classes Curr-acc & Sav-acc to make them more
specific to their requirements. Include necessary methods in order to achieve the
following tasks.
a) Accept deposit from a customer & update the balance
b) Display the balance
c) Compute & deposit interest
d) Permit withdrawal & update the balance
e) Check for the minimum balance, impose penalty if necessary & update the
balance
Do not use constructors. Use methods to initialize the class members.

2. Implement a superclass Person. Make 2 classes, Student & Instructor, inherit from
Person. A person has a name & year of birth. A student has a major, and an
instructor has a salary. Write the class definitions & methods for the classes.
Supply a test program that tests these classes & methods.

3. Make a class Employee with a name & salary. Make a class Manager inherit from
Employee. Add an instance variable, named department of type string. Supply a
method toString that prints the manager’s name, department & salary. Make a
class Executive inherit from Manager. Supply a methods toString that prints the
string “Executive”, followed by information stored in the Manager superclass
object. Supply a test program that test these classes & methods.

4. Create Student Class having following attributes: Student ID, Name, CourseID,
Sex and Phone Number.
Create hosteller who is a student having the following additional attributes:
HostelName and RoomNumber. Modify the room number and phone number.
Display the updated details.

5. Create Employee having following attributes: Emp ID, Name, Designation,


Project ID and Phone Number. An employee gets allocated to a new project. .
Create a PracticeHead who is an employee having the following additional
attributes: PracticeName, NoofCustomers. Add behavior to modify the
NoofCustomers and PhoneNumber. And display the updated PracticeHead details.

6. Create Product having following attributes: Product ID, Name, Category ID and
UnitPrice. Create ElectricalProduct having the following additional attributes:

TCS Internal
OOP Exercise Set 3

VoltageRange and Wattage. Add a behavior to change the Wattage and price of
the electrical product. Display the updated ElectricalProduct details.

7. Create Book having following attributes: Book ID, Title, Author and Price.
Create Periodical which has the following additional attributes: Period (weekly,
monthly etc...) .Add a behavior to modify the Price and the Period of the
periodical. Display the updated periodical details.

8. Create Vehicle having following attributes: Vehicle No., Model, Manufacturer


and Color. Create truck which has the following additional attributes:loading
capacity( 100 tons…).Add a behavior to change the color and loading capacity.
Display the updated truck details.
POLYMORPHISM

9. Write a program which performs to raise a number to a power and returns the
value. Provide a behavior to the program so as to accept any type of numeric
values and returns the results.

10. Illustrate a mechanism where you can provide a behavior for opening a door,
window, bank account, conversation, box etc.
(Note:- have an open() method with arguments, door, window, bank account)

11. Write a function Model-of-Category for a Tata motor dealers, which accepts
category of car customer is looking for and returns the car Model available in that
category. the function should accept the following categories "SUV", "SEDAN",
"ECONOMY", and "MINI" which in turn returns "TATA SAFARI" , "TATA
INDIGO" , "TATA INDICA" and "TATA NANO" respectively.

12. Overload the method volume() to calculate the volume of a


cube(s*s*s),cylinder(3.14*r*r*h),rectangle(l*b*h).

13. Write a superclass Worker & subclass HourlyWorker & SalariedWorker. Every
worker has a name & a salary rate. Write a method computePay(int hours) that
computes the weekly pay for every worker. An hourly worker gets paid the hourly
wage for the actual number of hours worked, if hours is at most 40. If the hourly
worker worked more than 40 hrs, the excess is paid at time &half. The salaried
worker gets paid the hourly wage for 40 hours, no matter what the actual number
of hours is. Write a method that uses polymorphism to compute the pay of any
Worker. Supply a test program that test these classes & methods.

TCS Internal

S-ar putea să vă placă și