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

OOPS_TUESDAY_BATCH_QUESTIONS[1]

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)
16 views3 pages

OOPS_TUESDAY_BATCH_QUESTIONS[1]

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

OOPS TUESDAY BATCH QUESTIONS

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

5.Write a program to check if a given number is a Kaprekar number using loops


Square the number nnn.
Split the squared number into two parts.
The right part should have as many digits as the original number nnn.
The left part can have the remaining digits.
Sum the two parts.
If the sum equals the original number nnn, then nnn is a Kaprekar number.

Example of Kaprekar Numbers:


45:
Square of 45: 452=202545^2 = 2025452=2025.
Split into two parts: 20 and 25.
Sum: 20+25=4520 + 25 = 4520+25=45.
45 is a Kaprekar number.
2.297:
Square of 297: 2972=88209297^2 = 882092972=88209.
Split into two parts: 88 and 209.
Sum: 88+209=29788 + 209 = 29788+209=297.
297 is a Kaprekar number.

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.

Run-Time Polymorphism (Method Overriding):


Create an abstract class LibraryUser with an abstract method getMembershipType()
which is overridden by its subclasses.
Implement subclasses Student, Teacher, and Visitor. Each subclass should override the
getMembershipType() method:
The Student class should return "Student Membership: Borrow limit 5 books."
The Teacher class should return "Teacher Membership: Borrow limit 10 books."
The Visitor class should return "Visitor Membership: Borrow limit 2 books."

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.

You might also like