0% found this document useful (0 votes)
0 views6 pages

OOPS Sample Questions

The document contains a list of sample questions for an Object Oriented Programming course, focusing on Java concepts such as constructors, user-defined classes, method overloading, inheritance, exception handling, collections, generics, threading, and JavaFX GUI applications. Each question requires the implementation of specific programming tasks, demonstrating various OOP principles and Java features. The questions range from basic class design to more complex scenarios involving multithreading and inter-thread communication.

Uploaded by

VAISHNAVI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views6 pages

OOPS Sample Questions

The document contains a list of sample questions for an Object Oriented Programming course, focusing on Java concepts such as constructors, user-defined classes, method overloading, inheritance, exception handling, collections, generics, threading, and JavaFX GUI applications. Each question requires the implementation of specific programming tasks, demonstrating various OOP principles and Java features. The questions range from basic class design to more complex scenarios involving multithreading and inter-thread communication.

Uploaded by

VAISHNAVI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

CSE 2005 Object Oriented Programming

List 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

Faculty Student Researchers


class class 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.

9. Apply the multiple inheritance using java interface.


Pavan and Arjun went for shopping at evening. Pavan wants to buy ten shirts at the price
Rs.1,000/- using first interface. Use the method shirts() to calculate the total amount. Arjun
is desired to get five gifts at 500/- using second interface. Use the gift() method for
computing the total amount. Both interfaces are implemented in class Main. Invoke the
shirts() and gift() to provide the total amount of shirts and gift. Feed the input from a user..
a. Display the total amount to be paid by each person separately.

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

11. Design a following multilevel inheritance hierarchy.


Managing Director

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}

14. Apply the Java Collections for the following problem.


Event Manager has prepared the list of people who are attending the function. Design
a program to list out the attendees with variables such as ID, name,
total_family_members. Implement the List interface using ArrayList and display the
added records.
i. If total_family_members > 3 and total_family_members < 6, allot the “First
Dining Hall”
ii. If total_family_members <=3, allot the “Second Dining Hall”
iii. Otherwise allot the “Third Dining Hall”

Print the ID, Name and Allotted Hall.

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.

16. Apply the generics to develop a java program.


The two members went for shopping. First member bought 5 grocery items at 500, 80, 250,
430, and 700. Second person bought five grocery items at 700.00, 150.50, 320.25, 340.25,
and 450.25. The cashier has computed the total amount for the bill. Which person will pay
more amount? Help the cashier by applying wildcard.
17. Apply the threading by implementing Runnable Interface.
Apply thread 1 for the following statement.
The salesman1 has collected the sales amount as 15000.50, 5500.75, 27000.00.
Apply thread 2 for the following statement.
The salesman2 has collected the sales amount as 69000.25, 7000.50 from the
customers.
Design a program to list out the sales amount and total_sales_amount of salesman 1
and salesman 2 separately.

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.

19. Apply the thread synchronization to print the multiplication table.


The school kid wants to learn the 5th and 6th multiplication table. Apply the thread 1 for 5th
table and thread 2 for 6th table. Design a java program to help the school kid to list out the
5th and 6th table.
Sample output:
5x1=5
5 x 2 = 10
….
6x1=6
6 x 2 = 12
….

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

Average of CAT 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.

4. Write a JavaFX program that creates a menu as shown below:


1. Apply the inter-thread communication (Producer – consumer) for the following
scenario.
The Shopkeeper displaying the milk-powder packs in the 10 empty trays in
supermarket. In Each tray, shopkeeper can place one pack only. He has 12 milk-
powder packs in the box. He can place the new pack (from the box) after selling the
displayed pack in the tray. Once the tray is full, display the message the “Tray is
full. Packs still avail in the box’. If tray is free, display the message “Tray is free”.

You might also like