๐Ÿงพ Java OOP Practical Exam โ€“ Set 7 (Detailed & Structured)

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


๐Ÿ“Œ Instructions:

  • Attempt all questions.
  • Write each program in separate classes.
  • Use proper OOP principles.
  • Use Scanner class wherever input is required.
  • Output must be clearly labeled.
  • Add comments to explain your code.

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


Q1. Class, Object & Constructor (10 Marks)

An online course platform wants to store and display course information.

๐Ÿ‘‰ Write a Java program following the steps below:

  1. Create a class named Course.
  2. Declare the following instance variables:
    • courseId (int)
    • courseName (String)
    • duration (in hours, int)
    • fee (double)
  3. Create a parameterized constructor:
    • It should accept values for all variables
    • Initialize them using the this keyword
  4. Create a method named displayCourseDetails():
    • This method should print all course details in a proper format
    • Example: Course ID: 201
      Course Name: Java Programming
      Duration: 40 hours
      Fee: 5000.0
  5. In the main() method:
    • Ask the user to enter details for 2 courses
    • Create objects using constructor
    • Display details of both courses

Q2. Inheritance & Method Overriding (10 Marks)

A utility billing system calculates electricity bills differently for different consumers.

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

  1. Create a base class ElectricityBill:
    • Method calculateBill(int units)
    • Default implementation should print: Bill calculation not defined
  2. Create two subclasses:
    • DomesticUser
    • CommercialUser
  3. Override the method in both classes:
    • DomesticUser:
      • Bill = units ร— โ‚น3
    • CommercialUser:
      • Bill = units ร— โ‚น5
  4. In the main() method:
    • Ask user to enter number of units consumed
    • Create objects of both subclasses
    • Call the method and display bill
  5. Output should clearly indicate:
    • Type of user
    • Units consumed
    • Total bill

Q3. Encapsulation (10 Marks)

A payroll system must securely handle employee salary details.

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

  1. Create a class Payroll.
  2. Declare private variables:
    • employeeId (int)
    • employeeName (String)
    • basicSalary (double)
  3. Provide:
    • Getter and Setter methods
  4. Add validation:
    • basicSalary should be greater than 0
    • If invalid, display "Invalid salary entered"
  5. Create a method calculateNetSalary():
    • HRA = 20% of basic salary
    • DA = 10% of basic salary
    • Net Salary = basic + HRA + DA
  6. In the main() method:
    • Create object
    • Set values using setters
    • Call method to calculate and display net salary

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


Q4. Abstract Class (10 Marks)

A notification system sends alerts using different channels.

๐Ÿ‘‰ Write a Java program as follows:

  1. Create an abstract classNotification:
    • Abstract method sendNotification(String message)
  2. Create subclasses:
    • EmailNotification
    • SMSNotification
  3. Implement method:
    • Email โ†’ print "Sending Email: message"
    • SMS โ†’ print "Sending SMS: message"
  4. In the main() method:
    • Use abstract class reference
    • Create objects of both subclasses
    • Call methods
  5. Ensure:
    • Proper abstraction
    • Dynamic method calling

Q5. Runtime Polymorphism (10 Marks)

A parking system calculates parking fees differently based on vehicle type.

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

  1. Create a class Parking:
    • Method calculateFee(int hours)
    • Default behavior: return 0
  2. Create subclasses:
    • TwoWheeler
    • FourWheeler
  3. Override method:
    • TwoWheeler โ†’ โ‚น10 per hour
    • FourWheeler โ†’ โ‚น20 per hour
  4. In the main() method:
    • Use parent class reference
    • Assign objects of both subclasses
    • Calculate and display fees
  5. Output must clearly show:
    • Vehicle type
    • Hours
    • Total fee

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

Q6. Exception Handling with Multiple Catches

๐Ÿ‘‰ Write a Java program to:

  1. Take input from user:
    • Array size
    • Array elements
  2. Then ask user for index to access element
  3. Handle exceptions:
    • Invalid input โ†’ InputMismatchException
    • Invalid index โ†’ ArrayIndexOutOfBoundsException
  4. Use:
    • Multiple catch blocks
    • 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 *