๐Ÿงพ Java OOP Practical Exam โ€“ Set 11 (Detailed & Student-Friendly)

โฑ๏ธ 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:

  1. Create a class named Room.
  2. Declare the following instance variables:
    • roomNumber (int)
    • roomType (String)
    • pricePerNight (double)
  3. Create a parameterized constructor:
    • It should accept values for all variables
    • Initialize them using the this keyword
  4. Create a method displayRoomDetails():
    • Display all details in a clear format: Room Number: 101
      Room Type: Deluxe
      Price per Night: 3000.0
  5. 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:

  1. Create a base class Ticket:
    • Method calculatePrice(int seats)
    • Default message: Price calculation not defined
  2. Create two subclasses:
    • RegularTicket
    • VIPTicket
  3. Override the method:
    • RegularTicket โ†’ โ‚น200 per seat
    • VIPTicket โ†’ โ‚น500 per seat
  4. In the main() method:
    • Ask user to enter number of seats
    • Create objects of both subclasses
    • Calculate and display total price
  5. 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:

  1. Create a class Result.
  2. Declare private variables:
    • rollNumber (int)
    • studentName (String)
    • marks (double)
  3. Provide:
    • Getter and Setter methods
  4. Add validation:
    • Marks should be between 0 and 100
    • If invalid, display "Invalid marks entered"
  5. Create a method calculateGrade():
    • Marks โ‰ฅ 75 โ†’ Grade A
    • Marks โ‰ฅ 50 โ†’ Grade B
    • Marks < 50 โ†’ Grade C
  6. 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:

  1. Create an abstract classShape:
    • Abstract method calculateArea()
  2. Create subclasses:
    • Circle
    • Rectangle
  3. Implement method:
    • Circle โ†’ Area = ฯ€ ร— r ร— r
    • Rectangle โ†’ Area = length ร— breadth
  4. In the main() method:
    • Take input for radius, length, breadth
    • Use abstract class reference
    • Call methods for both shapes
  5. 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:

  1. Create a class Salary:
    • Method calculateSalary()
    • Default: return 0
  2. Create subclasses:
    • Intern
    • FullTime
  3. Override method:
    • Intern โ†’ โ‚น10,000 fixed
    • FullTime โ†’ โ‚น30,000 fixed
  4. In the main() method:
    • Use parent class reference
    • Assign subclass objects
    • Display salary
  5. 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:

  1. Ask user to enter:
    • Two numbers
    • An operator (+, -, *, /)
  2. Perform calculation based on operator
  3. Handle:
    • Division by zero
    • Invalid operator
  4. Use:
    • try-catch
    • finally block to print:

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *