🧾 Java OOP Practical Exam – Set 14 (Advanced + Carefully Structured)

⏱️ Time: 2 Hours
πŸ“Š Maximum Marks: 50


πŸ“Œ Instructions (Read Carefully):

  • Attempt all questions.
  • Write each program in a separate class/file.
  • Follow proper OOP principles and structure.
  • Use Scanner class for input wherever required.
  • Output must be clearly labeled and formatted.
  • Add comments explaining important logic and decisions.

πŸ”Ή Section A – Core Programming (30 Marks)


Q1. Class, Constructor & Multi-Condition Logic (10 Marks)

πŸ“˜ Scenario: Movie Ticket Billing System

A cinema calculates ticket price based on show type and number of tickets.

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

  1. Create a class MovieTicket.
  2. Declare instance variables:
    • movieName (String)
    • showType (String) (β€œMorning” or β€œEvening”)
    • numberOfTickets (int)
    • pricePerTicket (double)
  3. Create a parameterized constructor:
    • Initialize all variables using this
  4. Create a method calculateTotal():
    • Base total = numberOfTickets Γ— pricePerTicket
    • If showType = “Evening” β†’ add 20% extra charge
    • If numberOfTickets β‰₯ 5 β†’ give 10% discount on final amount
  5. Create method displayDetails():
    • Display all details including final amount
  6. In the main() method:
    • Take input from user
    • Create object
    • Display result

Q2. Inheritance + Overriding + Combined Logic (10 Marks)

πŸ“˜ Scenario: Courier Service Pricing

A courier company charges based on package type and weight.

πŸ‘‰ Write a Java program as follows:

  1. Create base class Courier:
    • Method calculateCost(double weight)
    • Default message: Cost calculation not available
  2. Create subclasses:
    • DocumentCourier
    • ParcelCourier
  3. Override method:
    • DocumentCourier:
      • β‚Ή5 per kg
      • Minimum charge β‚Ή50 (if calculated < 50, charge 50)
    • ParcelCourier:
      • β‚Ή10 per kg
      • If weight > 10 kg β†’ add β‚Ή100 extra
  4. In the main() method:
    • Take weight as input
    • Create objects
    • Display calculated cost
  5. Output must show:
    • Courier type
    • Weight
    • Final cost

Q3. Encapsulation + Transaction Rules (10 Marks)

πŸ“˜ Scenario: Digital Wallet with Limits

A wallet system enforces transaction limits and balance rules.

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

  1. Create class DigitalWallet.
  2. Declare private variables:
    • walletId (int)
    • userName (String)
    • balance (double)
  3. Provide getter and setter methods:
    • Balance must not be negative
  4. Create methods:
    • addFunds(double amount)
    • makePayment(double amount)
  5. Add conditions:
    • Maximum payment allowed per transaction = β‚Ή5000
    • Balance must remain β‰₯ β‚Ή200 after payment
    • Otherwise display: Transaction declined
  6. In the main() method:
    • Perform multiple operations
    • Display final balance

πŸ”Ή Section B – Advanced OOP Concepts (20 Marks)


Q4. Abstract Class + Multi-Step Processing (10 Marks)

πŸ“˜ Scenario: Billing System for Utilities

Different utilities calculate bills differently but share common display logic.

πŸ‘‰ Write a Java program as follows:

  1. Create an abstract classUtilityBill:
    • Abstract method calculateBill(int usage)
    • Concrete method displayMessage() β†’ prints "Bill Generated Successfully"
  2. Create subclasses:
    • WaterBill
    • InternetBill
  3. Implement method:
    • WaterBill:
      • β‚Ή2 per unit
      • If usage > 100 β†’ add β‚Ή50 extra
    • InternetBill:
      • β‚Ή500 fixed
      • If usage > 500 β†’ add β‚Ή100 extra
  4. In the main() method:
    • Take usage input
    • Call both methods
  5. Output must show:
    • Type of bill
    • Usage
    • Total amount

Q5. Runtime Polymorphism + Multiple Conditions (10 Marks)

πŸ“˜ Scenario: Insurance Premium System

Different policies calculate premium differently.

πŸ‘‰ Write a Java program:

  1. Create class Insurance:
    • Method calculatePremium(double amount)
    • Default: return 0
  2. Create subclasses:
    • HealthInsurance
    • VehicleInsurance
  3. Override method:
    • HealthInsurance:
      • Premium = 5% of amount
      • If amount > 5,00,000 β†’ add β‚Ή2000 extra
    • VehicleInsurance:
      • Premium = 3% of amount
      • Minimum premium β‚Ή1000
  4. In the main() method:
    • Take amount as input
    • Use parent reference
    • Display premium
  5. Output must clearly show:
    • Insurance type
    • Amount
    • Premium

⭐ Bonus Question (Optional – 5 Marks)

Q6. Exception Handling + Custom Logic

πŸ“˜ Scenario: Login Attempt Limiter

πŸ‘‰ Write a Java program to:

  1. Allow user to enter password
  2. Conditions:
    • Correct password = "admin123"
    • Maximum 3 attempts allowed
  3. If:
    • Wrong password β†’ display "Incorrect password"
    • After 3 attempts β†’ throw exception "Account Locked"
  4. Use:
    • Loop + try-catch
  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 *