๐Ÿงพ Java OOP Practical Exam โ€“ Set 12 (Detailed + Slightly Advanced)

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


๐Ÿ“Œ Instructions (Read Carefully):

  • Attempt all questions.
  • Each question must be written in a separate class/file.
  • Follow proper OOP concepts and structure.
  • Use Scanner class wherever input is required.
  • Output must be clearly formatted and labeled.
  • Add comments to explain important logic.

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


Q1. Class, Object, Constructor & Method Logic (10 Marks)

๐Ÿ“˜ Scenario: Electricity Usage Tracker

An electricity department wants to track usage and calculate monthly bill.

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

  1. Create a class named ElectricityUsage.
  2. Declare the following instance variables:
    • consumerId (int)
    • consumerName (String)
    • unitsConsumed (int)
  3. Create a parameterized constructor:
    • Initialize all variables using this keyword
  4. Create a method calculateBill():
    • If units โ‰ค 100 โ†’ โ‚น2 per unit
    • If units โ‰ค 300 โ†’ โ‚น4 per unit
    • If units > 300 โ†’ โ‚น6 per unit
  5. Create a method displayDetails():
    • Display consumer details
    • Display calculated bill
  6. In the main() method:
    • Take input for one consumer
    • Create object
    • Display details

Q2. Inheritance + Overriding with Extra Logic (10 Marks)

๐Ÿ“˜ Scenario: Online Course Pricing

Different courses have different pricing rules.

๐Ÿ‘‰ Write a Java program as follows:

  1. Create base class Course:
    • Method calculateFee(int duration)
    • Default message: Fee calculation not defined
  2. Create subclasses:
    • ProgrammingCourse
    • DesignCourse
  3. Override method:
    • ProgrammingCourse:
      • Fee = duration ร— โ‚น100
      • If duration > 30 โ†’ apply 10% discount
    • DesignCourse:
      • Fee = duration ร— โ‚น80
  4. In the main() method:
    • Take duration as input
    • Create objects of both subclasses
    • Display calculated fee
  5. Output must clearly show:
    • Course type
    • Duration
    • Final fee

Q3. Encapsulation with Business Logic (10 Marks)

๐Ÿ“˜ Scenario: Mobile Recharge System

A telecom company manages user balance securely.

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

  1. Create a class RechargeAccount.
  2. Declare private variables:
    • mobileNumber (String)
    • userName (String)
    • balance (double)
  3. Provide:
    • Getter and Setter methods
  4. Add validation:
    • Balance cannot be negative
  5. Create methods:
    • recharge(double amount) โ†’ add balance
    • makeCall(int minutes):
      • Deduct โ‚น1 per minute
      • If insufficient balance โ†’ display "Low balance"
  6. In the main() method:
    • Create object
    • Perform recharge
    • Simulate call
    • Display final balance

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


Q4. Abstract Class with Multiple Methods (10 Marks)

๐Ÿ“˜ Scenario: Report Generation System

Different report types generate output differently.

๐Ÿ‘‰ Write a Java program as follows:

  1. Create an abstract classReport:
    • Abstract method generateReport()
    • Concrete method printHeader() โ†’ prints "Report Generated"
  2. Create subclasses:
    • SalesReport
    • StudentReport
  3. Implement abstract method:
    • SalesReport โ†’ "Generating Sales Report"
    • StudentReport โ†’ "Generating Student Report"
  4. In the main() method:
    • Use abstract class reference
    • Call both methods (printHeader() and generateReport())

Q5. Runtime Polymorphism with Return Values (10 Marks)

๐Ÿ“˜ Scenario: Tax Calculation System

Different income types have different tax rules.

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

  1. Create a class Tax:
    • Method calculateTax(double income)
    • Default: return 0
  2. Create subclasses:
    • SalariedTax
    • BusinessTax
  3. Override method:
    • Salaried โ†’ 10% of income
    • Business โ†’ 20% of income
  4. In the main() method:
    • Take income as input
    • Use parent class reference
    • Assign subclass objects
    • Display tax for both
  5. Output must clearly show:
    • Income type
    • Tax calculated

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

Q6. Exception Handling + Custom Validation

๐Ÿ“˜ Scenario: Password Validation System

๐Ÿ‘‰ Write a Java program to:

  1. Ask user to enter password
  2. Validate:
    • Length must be at least 6 characters
  3. If invalid:
    • Throw exception with message "Weak Password"
  4. Use:
    • try-catch
    • throw keyword
  5. Finally block should 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 *