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

OOPS Programs

The document outlines a series of programming problems requiring the design and implementation of various classes in Java. Each problem specifies class structures, data members, and methods to perform specific tasks, such as handling time, calculating areas, and demonstrating polymorphism. The problems also include creating constructors, method overloading, and inheritance concepts to manage different scenarios.

Uploaded by

amiyapanigrahi09
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)
33 views3 pages

OOPS Programs

The document outlines a series of programming problems requiring the design and implementation of various classes in Java. Each problem specifies class structures, data members, and methods to perform specific tasks, such as handling time, calculating areas, and demonstrating polymorphism. The problems also include creating constructors, method overloading, and inheritance concepts to manage different scenarios.

Uploaded by

amiyapanigrahi09
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/ 3

Problem1:

Design a class 'Time' with the following specifications:


class Time
Data members/Instance variables
int hour, min, sec
Member Methods:
void get_time( ) : to accept a time in hour, minute and second.
void show_time( ) : to display the time in terms of hour, minute and second.
Write a main method to create an object of class 'Time' and call the member methods.
Problem2:

Design a class 'Rectangle' with the following specifications:


class Rectangle
Data members/Instance variables
int length, breadth, area, perimeter
Member methods:
void input( ) : to accept length and breadth of a rectangle.
void calculate( ) : to calculate area and perimeter of rectangle.
void display( ) : to print area and perimeter of rectangle.
Write a main method to create an object of class 'Rectangle' and call the member methods.
Problem3:

Write a class template 'Calculator' with the following specifications:


class Calculator
Data members/Instance variables
int a,b,c
Member Methods:
void readdata( ) : to accept the values of a and b.
void add( ) : to add a and b and place the result in c.
void sub( ) : to subtract b from a and place the result in c. Display the result.
void mul( ) : to multiply a and b and place the result in c. Display the result.
void div( ) : to divide a by b and place the result in c. Display the result.
Write a main method to create an object of class 'Calculator' and call the member methods to
enable the task.
Problem4:
Create a class named 'PrintNumber' to print various numbers of different datatypes by creating
different methods with the same name 'printn' having a parameter for each datatype.

Problem 5:

Create a class to print an integer and a character with two methods having the same name but
different sequence of the integer and the character parameters.
For example, if the parameters of the first method are of the form (int n, char c), then that of the
second method will be of the form (char c, int n).

Problem 6:
Create a class to print the area of a square and a rectangle. The class has two methods with the
same name but different number of parameters. The method for printing area of rectangle has
two parameters which are length and breadth respetively while the other method for printing area
of square has one parameter which is side of square.

Problem7:

Create a class 'Student' with three data members which are name, age and address. The
constructor of the class assigns default values name as "unknown", age as '0' and address as "not
available". It has two members with the same name 'setInfo'. First method has two parameters for
name and age and assigns the same whereas the second method takes has three parameters which
are assigned to name, age and address respectively. Print the name, age and address of 10
students.
Hint - Use array of objects

Problem8:

Create a class 'Degree' having a method 'getDegree' that prints "I got a degree". It has two
subclasses namely 'Undergraduate' and 'Postgraduate' each having a method with the same name
that prints "I am an Undergraduate" and "I am a Postgraduate" respectively. Call the method by
creating an object of each of the three classes.

Problem9:
A boy has his money deposited $1000, $1500 and $2000 in banks-Bank A, Bank B and Bank C
respectively. We have to print the money deposited by him in a particular bank.
Create a class 'Bank' with a method 'getBalance' which returns 0. Make its three subclasses
named 'BankA', 'BankB' and 'BankC' with a method with the same name 'getBalance' which
returns the amount deposited in that particular bank. Call the method 'getBalance' by the object
of each of the three banks.

Problem10:
A class has an integer data member 'i' and a method named 'printNum' to print thevalue of 'i'. Its
subclass also has an integer data member 'j' and a method named 'printNum' to print the value of
'j'. Make an object of the subclass and use it to assign a value to 'i' and to 'j'. Now call the method
'printNum' by this object.

Problem11;

Suppose a class 'A' has a static method to print "Parent". Its subclass 'B' also has a static method
with the same name to print "Child". Now call this method by the objects of the two classes.
Also, call this method by an object of the parent class refering to the child class i.e. A obj = new
B()

Problem 12:

All the banks operating in India are controlled by RBI. RBI has set a well defined guideline (e.g.
minimum interest rate, minimum balance allowed, maximum withdrawal limit etc) which all
banks must follow. For example, suppose RBI has set minimum interest rate applicable to a
saving bank account to be 4% annually; however, banks are free to use 4% interest rate or to set
any rates above it.

Write a JAVA program to implement bank functionality in the above scenario and demonstrate
the dynamic polymorphism concept. Note: Create few classes namely Customer, Account, RBI
(Base Class) and few derived classes (SBI, ICICI, PNB etc). Assume and implement required
member variables and functions in each class.

Problem 13:

Write a program to print the names of students by creating a Student class. If no name is passed
while creating an object of Student class, then the name should be "Unknown", otherwise the
name should be equal to the String value passed while creating object of Student class.

You might also like