OOPS Sample Questions
OOPS Sample Questions
1. Apply the constructor for displaying the progress report of project. Invoke the
constructor by instantiating an object.
i. Use the default constructor to display the project title.
ii. Pass the duration as an argument to the constructor. If duration > 15 days and
duration < 25 days, print the “Testing Period for the Project”. If duration >= 25, print
the “Delivery and Installation in Customer Premises”. Otherwise, print “Coding Period
for the Project”.
2. Create a user defined class for Bicycle with features Brandname, BrandID, Price, Qty,
Total_Amount. Assign the values to these features using set_Values() method and
retrieve the details using Show_details(). Invoke the methods by instantiating an object.
3. Create a user defined class for overloading with features book_id, book_title,
Author_name. Invoke the methods by instantiating an object. Pass the values to these
features through invoking method.
i. Define the method show(String book_title) to display the book title.
ii. Define the method show(int book_id, String book_title) to display the book ID and
title.
iii. Define the method show(int book_id, String book_title, String Author_name) to
display the book_id, book_title and Author_name.
4. The Furniture shop contains the different furniture such as Cot, Chair, Table, etc.,
Create an array of furniture object with size 5 in user defined class. Define the variables
brandname, furniture_type, qty, price, total_amount. Feed the input from a user.
i. Provide the 10% offer to the customer if total amount > 5000.
ii. Find the largest quantity purchased furniture_type.
5. The school kid wants to perform arithmetic operations in the mathematics period. The
kid wrote three numbers in different primitive data types such as one int value, one
float value, and one string value. E.g., 120, 20.5f, “1052”.
i. Apply the wrapper class methods to convert into required data types.
ii. Find the total and average of these input.
iii. Average data type should be in Double.
6. Akhil was reading the “The Hindu” newspaper. He has a curiosity to count the
appearance “E” in each paragraph. Help him by designing a java program using
wrapper class to count the appearance of “E”.
i. Enter the paragraph using scanner class.
ii. Apply the wrapper class to count the appearance of “E”.
7. Design a following hierarchy.
Stakeholder class
Each stakeholder has following attributes id, name. The derived classes contain the following
attributes: position_id, position_title. All classes contains print() to display details. Create a
“University” class to create all objects and print all objects.
i. Print each object’s id, name, position_id, position_title.
8. Apply the method overriding for the following problem.
The merchant has 10 kinds of products in the shop. Each product is purchased for different
price. He has checked the invoice to pay the amount to the suppliers. The invoice contains
productname, qty, price. Design a java program to help him to know the total payable
amount to the supplier.
i. Create the abstract class with method payable_amount().
ii. Create the user defined class which implements the payable_amount() method which
inherits the abstract class.
iii. Invoke the methods using an object. Feed the input from the user.
10. Design a package using java program. The tourists are planned rent a house for certain
period in the Goa. The rent per day is Rs.3,000. Create a package with a class Room_Rent
to provide the with features such as breakfast_foodnames, Dinner_foodnames, rent_amount.
Import this package to another class Expenses with attributes like total_expenses, discount,
duration. Discount will be provided as per following criteria.
• If total_expenses > 15000, discount is 10%.
• If total_expenses <10000, discount is 5%.
• Feed the input from a user
Manager
Salesmen
The Managing Director class contains the features game_id, game_name, no_of_players,
price. The Manager class inherits those features. The manager class contains the method
manage_sales() that computes the quantity sold by three managers. The salesmen class
contains the method salesmen_sales() that computes the quantity sold by five salesmen.
Help to the Managing Director to calculate the total amount given by managers and
salesmen.
12. Apply the Exception handling for the following problem.
The Electrical shop contains different electrical products with many brands and price.
Develop a java program with a user defined class with the following properties.
Datatype Variable Value
String brandname null
Int ID 1011
String Itemname “Table Lamp”
Double Price 1000
Create the method set_details() to assign the given data in the table to the variables. Print the
electrical product details to the user using print() method. Use the throws clause and handle
the exception. Feed the using scanner class.
13. Apply the user defined exception for the following program.
The kitchen contains six items in the shelf. Create a class Kitchen with features Item_name and
Item_Ids. Design a class ItemIdException and throw exception when user enters the invalid Item_ids
greater than 500 and less than 0. Create a class Item_nameException and throw exception when user
enters invalid Item names i.e., other than given six item names. Write the output.
Item_name {salt, tomatoes, cumin, turmeric, ginger, garlic}
Item_Ids {101, 102, 103, 104, 105, 106}
15. Apply the generics to develop a java program for train ticket reservation.
Create a user defined class features such as pnr_no, passenger_name, age, source,
destination. Allot “Lower Berth” if age >40, “Upper Berth” if age is between 18 to 40,
“Middle Berth” if age < 19.
i. pnr as String datatype.
ii. pnr as int datatype.
iii. pnr as float data type.
Sample Output:
Salesman1 Collected from Customer 1: 15000.50
Salesman2 Collected from Customer 1: 69000.25
Salesman1 Collected from Customer 2: 5500.75
Salesman2 Collected from Customer2: 7000.50
Salesman1 Collected from Customer 3: 27000.00
Salesman2 Collected Amount: 76000.75
Salesman1 Collected Amount: 47501.25
18. Apply the multithreading using interrupted() method.
Two members are entering into the shopping mall. The shopping mall contains the two
checking counters in front of the mobiles shop to prevent the customers taking their things
inside. The two persons are entered the checking counter1 one by one which allows them.
But checking counter2 interrupted the first person and allowed the second person.
Apply the thread 1 for first person, thread 2 for second person.
Sample output:
Both are allowed in Counter 1
Second Person allowed in counter 2 and First person is not allowed in counter2.
1. The following JavaFX GUI counter contains 3 controls (or components): a Label, a
Text Field and a Button. Clicking the button increases the count displayed in the text
field.
2. Create javaFx application using Label, button and Textfield controls as follows.
Roll No
Name
Branch
CAT1 Marks
CAT2 Marks
Exit
3. Write a JavaFX program that works as a simple calculator. Use a grid layout to
arrange buttons for the digits and for the +, -, *, % operations. Add a text field to
display the result. Handle any possible exceptions like divide by zero.