โฑ๏ธ Time: 2 Hours
๐ Maximum Marks: 50
๐ Instructions (Read Carefully):
- Attempt all questions.
- Write each program in a separate class/file.
- Use proper OOP concepts and naming conventions.
- Use Scanner class for user input wherever required.
- Output should be well formatted and clearly labeled.
- Add comments to explain your code.
๐น Section A โ Core Programming (30 Marks)
Q1. Class, Object & Constructor (10 Marks)
๐ Scenario: Hotel Room Booking System
A hotel wants to store details of rooms and display them to customers.
๐ Write a Java program with the following requirements:
- Create a class named
Room. - Declare the following instance variables:
- roomNumber (int)
- roomType (String)
- pricePerNight (double)
- Create a parameterized constructor:
- It should accept values for all variables
- Initialize them using the
thiskeyword
- Create a method
displayRoomDetails():- Display all details in a clear format:
Room Number: 101
Room Type: Deluxe
Price per Night: 3000.0
- Display all details in a clear format:
- In the
main()method:- Ask the user to enter details for 2 rooms
- Create objects using constructor
- Display details of both rooms
Q2. Inheritance & Method Overriding (10 Marks)
๐ Scenario: Ticket Booking System
A ticket booking system calculates ticket price based on category.
๐ Write a Java program as follows:
- Create a base class
Ticket:- Method
calculatePrice(int seats) - Default message:
Price calculation not defined
- Method
- Create two subclasses:
RegularTicketVIPTicket
- Override the method:
- RegularTicket โ โน200 per seat
- VIPTicket โ โน500 per seat
- In the
main()method:- Ask user to enter number of seats
- Create objects of both subclasses
- Calculate and display total price
- Output must clearly show:
- Ticket type
- Number of seats
- Total price
Q3. Encapsulation (10 Marks)
๐ Scenario: Student Result System
A school wants to manage student marks securely.
๐ Write a Java program with the following requirements:
- Create a class
Result. - Declare private variables:
- rollNumber (int)
- studentName (String)
- marks (double)
- Provide:
- Getter and Setter methods
- Add validation:
- Marks should be between 0 and 100
- If invalid, display
"Invalid marks entered"
- Create a method
calculateGrade():- Marks โฅ 75 โ Grade A
- Marks โฅ 50 โ Grade B
- Marks < 50 โ Grade C
- In the
main()method:- Create object
- Set values using setters
- Display student details and grade
๐น Section B โ Advanced OOP Concepts (20 Marks)
Q4. Abstract Class (10 Marks)
๐ Scenario: Shape Area Calculation System
Different shapes calculate area differently.
๐ Write a Java program as follows:
- Create an abstract class
Shape:- Abstract method
calculateArea()
- Abstract method
- Create subclasses:
CircleRectangle
- Implement method:
- Circle โ Area = ฯ ร r ร r
- Rectangle โ Area = length ร breadth
- In the
main()method:- Take input for radius, length, breadth
- Use abstract class reference
- Call methods for both shapes
- Output must clearly display:
- Shape type
- Calculated area
Q5. Runtime Polymorphism (10 Marks)
๐ Scenario: Salary Calculation System
Different employees have different salary structures.
๐ Write a Java program with the following steps:
- Create a class
Salary:- Method
calculateSalary() - Default: return 0
- Method
- Create subclasses:
InternFullTime
- Override method:
- Intern โ โน10,000 fixed
- FullTime โ โน30,000 fixed
- In the
main()method:- Use parent class reference
- Assign subclass objects
- Display salary
- Ensure:
- Runtime polymorphism is clearly demonstrated
- Output shows employee type and salary
โญ Bonus Question (Optional โ 5 Marks)
Q6. Exception Handling
๐ Scenario: Simple Calculator
๐ Write a Java program to:
- Ask user to enter:
- Two numbers
- An operator (+, -, *, /)
- Perform calculation based on operator
- Handle:
- Division by zero
- Invalid operator
- Use:
try-catchfinallyblock to print: