๐Ÿงพ Java OOP Practical Exam โ€“ Set 5 (Detailed Version)

โฑ๏ธ Time: 2 Hours
๐Ÿ“Š Maximum Marks: 50


๐Ÿ“Œ Instructions (Read Carefully):

  • Attempt all questions.
  • Each program must be written in separate classes.
  • Use proper indentation and comments.
  • Follow OOP principles strictly.
  • Wherever input is required, you may use Scanner class.
  • Display output in a clear and readable format.

๐Ÿ”น Section A โ€“ Core Programming (30 Marks)


Q1. Class, Object & Constructor (10 Marks)

A vehicle rental company wants to store and display details of vehicles available for rent.

๐Ÿ‘‰ You are required to write a Java program with the following specifications:

  1. Create a class named Vehicle.
  2. Declare the following data members:
    • vehicleNumber (String)
    • vehicleName (String)
    • rentPerDay (double)
  3. Create a parameterized constructor that:
    • Accepts values for all data members
    • Initializes them using this keyword
  4. Create a method named displayVehicleDetails() that:
    • Prints all the details in a proper format
    • Example format: Vehicle Number: MH12AB1234
      Vehicle Name: Swift
      Rent per Day: 1500
  5. In the main() method:
    • Create at least 3 vehicle objects with different values
    • Call the display method for each object

Q2. Inheritance & Method Overriding (10 Marks)

A school management system calculates exam results differently for different types of students.

๐Ÿ‘‰ Write a Java program as per the following instructions:

  1. Create a base class Student:
    • Data member: name
    • Method: calculateResult()
      • This method should print: "Result calculation not defined"
  2. Create two subclasses:
    • RegularStudent
    • DistanceStudent
  3. Override the calculateResult() method:
    • RegularStudent:
      • Assume marks = 80
      • Print: "Regular Student Passed" if marks โ‰ฅ 40
    • DistanceStudent:
      • Assume marks = 35
      • Print: "Distance Student Passed" or "Failed" accordingly
  4. In the main() method:
    • Create objects of both subclasses
    • Call the overridden method for each
  5. Ensure that:
    • Method overriding is clearly demonstrated
    • Output messages are clearly distinguishable

Q3. Encapsulation (10 Marks)

A banking system must ensure that account balance is handled securely.

๐Ÿ‘‰ Write a Java program with the following requirements:

  1. Create a class BankAccount.
  2. Declare private data members:
    • accountNumber (int)
    • accountHolderName (String)
    • balance (double)
  3. Provide public:
    • Setter methods to assign values
    • Getter methods to retrieve values
  4. Add validation inside setter:
    • Balance should not be negative
    • If negative value is given, display: "Invalid balance"
  5. Create a method deposit(double amount):
    • Adds amount to balance
    • Print updated balance
  6. Create a method withdraw(double amount):
    • Deduct amount if sufficient balance
    • Otherwise display: "Insufficient balance"
  7. In main():
    • Create an object
    • Set values using setters
    • Perform deposit and withdrawal operations
    • Display final account details

๐Ÿ”น Section B โ€“ Advanced OOP Concepts (20 Marks)


Q4. Abstract Class (10 Marks)

A company uses different types of employees, and their bonus calculation varies.

๐Ÿ‘‰ Write a Java program following these steps:

  1. Create an abstract classEmployee:
    • Data member: name
    • Abstract method: calculateBonus()
  2. Create two subclasses:
    • Manager
    • Developer
  3. Implement calculateBonus():
    • Manager โ†’ Bonus = โ‚น10,000
    • Developer โ†’ Bonus = โ‚น5,000
  4. Each method should:
    • Print employee type
    • Print bonus amount
  5. In main():
    • Use reference of abstract class
    • Create objects of both subclasses
    • Call methods using dynamic binding

Q5. Runtime Polymorphism (10 Marks)

An online shopping system applies different discount strategies.

๐Ÿ‘‰ Write a Java program as follows:

  1. Create a class Product:
    • Method applyDiscount(double price)
    • Default behavior: return original price
  2. Create subclasses:
    • Electronics
    • Clothing
  3. Override the method:
    • Electronics โ†’ 10% discount
    • Clothing โ†’ 20% discount
  4. In main():
    • Use parent class reference
    • Assign objects of both subclasses
    • Call method and print final price
  5. Clearly show:
    • Same method behaving differently for different objects

โญ Bonus Question (Optional โ€“ 5 Marks)

Q6. Exception Handling (Detailed)

๐Ÿ‘‰ Write a Java program to:

  1. Take two integers as input from the user:
    • numerator
    • denominator
  2. Perform division: result = numerator / denominator
  3. Handle the following cases:
    • If denominator = 0 โ†’ display "Cannot divide by zero"
    • If invalid input โ†’ handle using appropriate exception
  4. Use:
    • try
    • catch
    • finally block (to print "Operation completed")

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 *