OOPS_TUESDAY_BATCH_QUESTIONS[1]
OOPS_TUESDAY_BATCH_QUESTIONS[1]
1. Basic Java 1.Create a menu-driven program (use switch) that allows users to perform various
operations by reading three numbers.
The program should present a menu with the following options:
1. Add three numbers and check commutative property
2. From the Subtraction (a-(b-c)) and ((a-b)-c) and check commutative property
3. Find the LCM Of a,b,c
4. Exit
2.Write a java program is to count all unique possible paths from the top left to the
bottom right of a M X N matrix with the constraints that from each cell you can either
move only to the right or down
Examples:
Input: M = 2, N = 2
Output: 2
Explanation: There are two paths
(0, 0) -> (0, 1) -> (1, 1)
(0, 0) -> (1, 0) -> (1, 1)
Input: M = 2, N = 3
Output: 3
Explanation: There are three paths
(0, 0) -> (0, 1) -> (0, 2) -> (1, 2)
(0, 0) -> (0, 1) -> (1, 1) -> (1, 2)
(0, 0) -> (1, 0) -> (1, 1) -> (1, 2)
3.Read the range from the user and find the prime numbers within that range.
Implement a program to check if a number is a twin prime (part of a pair of primes that
differ by 2).
Examples :
Range : 10 and 15
• (11, 13): Both 11 and 13 are prime numbers, and the difference between them is 2.
Range: 15 and 22
• (17, 19): Both 17 and 19 are prime numbers, and the difference between them is 2.
4.Write a program to find the digital root of a given number (repeated sum of digits until
a single digit is obtained).
Exmple : 5678
Ans:8
2. Encapsulation Design a Car class that encapsulates the car’s make, model, year, rental price, and
availability. Then, create a CarRental class that manages the rental process. Provide
methods to rent a car, return a car, and check availability. The rental process should be
handled through methods, not by directly modifying the car’s availability
Key Concepts: Private fields, public methods (getters and setters), input validation.
3. Inheritance Manage a fleet of autonomous vehicles (cars, trucks, drones, etc.) where each type of
vehicle has its own specifications and operational parameters, but they share some
common properties such as fuel type, status monitoring, and location tracking.
Use of Inheritance: Vehicle can be the parent class, while Car, Truck, Drone, etc., inherit
from it.
Use of Static Methods: Track the total number of vehicles in the fleet and their current
operational status (e.g., number of vehicles in use vs. idle).
Abstract Methods: Define abstract methods like operate() (which would differ for a car,
truck, or drone) and fuelType() (which could be electric, gas, or hybrid).
4. Polymorphis You are tasked with designing a library management system that can handle different
m types of library users and actions they can perform. In this system, you need to
demonstrate both compile-time and run-time polymorphism.
Requirements:
Compile-Time Polymorphism (Method Overloading):
Create a class LibraryServices that provides methods for issuing books to users.
Implement the method issueBook with different signatures:
Method 1: Takes the int userId and the int bookId, and issues the book to the user.
Method 2: Takes the int userId, the int bookId, and the number of days for which the
book is issued (int days), and issues the book for that duration.
Method 3: Takes a String userName, a String bookTitle, and issues the book to the user
by name and book title.
Main Functionality:
In the main method, create objects of Student, Teacher, and Visitor.
Use method overloading in LibraryServices to issue books based on different
parameters.
Use method overriding to get the membership details for each user type.
5. Packages and
Interface
6. Exceptions Consider the Phone recharge billing system. Create the exceptions such as
NegativeValueException, InvalidPhoneNoException and use it in the appropriate places .
Use appropriate data members and methods to implement the system .
7. Threads Write a java program that creates two threads. First thread displays “odd number” in
every two seconds, the second thread displays “even number” in every three seconds.
Read the range of integers from the user.