๐Ÿงพ Java OOP Practical Exam โ€“ Set 13 (Detailed + Logic Twist)

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


๐Ÿ“Œ Instructions (Read Carefully):

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

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


Q1. Class, Constructor & Conditional Logic (10 Marks)

๐Ÿ“˜ Scenario: Parking Ticket System

A parking system calculates charges based on hours parked.

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

  1. Create a class ParkingTicket.
  2. Declare instance variables:
    • vehicleNumber (String)
    • hoursParked (int)
    • ratePerHour (double)
  3. Create a parameterized constructor:
    • Initialize all variables using this
  4. Create a method calculateCharges():
    • If hours โ‰ค 2 โ†’ charge = hours ร— rate
    • If hours > 2 โ†’ extra โ‚น20 added as service fee
  5. Create method displayDetails():
    • Display:
      • Vehicle number
      • Hours parked
      • Total charge
  6. In the main() method:
    • Take input from user
    • Create object
    • Display result

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

๐Ÿ“˜ Scenario: Delivery Charge System

A logistics company charges delivery fees based on service type and distance.

๐Ÿ‘‰ Write a Java program as follows:

  1. Create base class DeliveryService:
    • Method calculateCharge(double distance)
    • Default message: Delivery charge not defined
  2. Create subclasses:
    • LocalDelivery
    • IntercityDelivery
  3. Override method:
    • LocalDelivery:
      • โ‚น10 per km
      • If distance > 50 km โ†’ add โ‚น100 extra
    • IntercityDelivery:
      • โ‚น20 per km
  4. In the main() method:
    • Take distance as input
    • Create objects of both classes
    • Display charges
  5. Output must show:
    • Delivery type
    • Distance
    • Final charge

Q3. Encapsulation + Multi-Step Logic (10 Marks)

๐Ÿ“˜ Scenario: E-Wallet Transaction System

An e-wallet system handles balance and transactions securely.

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

  1. Create class EWallet.
  2. Declare private variables:
    • walletId (int)
    • userName (String)
    • balance (double)
  3. Provide getter and setter methods with validation:
    • Balance cannot be negative
  4. Create methods:
    • addMoney(double amount)
    • transferMoney(double amount)
  5. Add conditions:
    • Transfer allowed only if:
      • balance โ‰ฅ amount
      • minimum balance after transfer = โ‚น100
    • Otherwise display: Transaction not allowed
  6. In the main() method:
    • Create object
    • Perform multiple operations
    • Display final balance

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


Q4. Abstract Class with Logic (10 Marks)

๐Ÿ“˜ Scenario: Examination System

Different exams calculate grades differently.

๐Ÿ‘‰ Write a Java program as follows:

  1. Create an abstract classExam:
    • Abstract method calculateGrade(int marks)
  2. Create subclasses:
    • SchoolExam
    • CompetitiveExam
  3. Implement method:
    • SchoolExam:
      • โ‰ฅ 90 โ†’ A
      • โ‰ฅ 70 โ†’ B
      • else โ†’ C
    • CompetitiveExam:
      • โ‰ฅ 80 โ†’ Qualified
      • else โ†’ Not Qualified
  4. In the main() method:
    • Take marks as input
    • Use abstract class reference
    • Display results for both exams

Q5. Runtime Polymorphism + Conditional Output (10 Marks)

๐Ÿ“˜ Scenario: Ride Fare System

Different ride types calculate fare differently.

๐Ÿ‘‰ Write a Java program:

  1. Create class RideService:
    • Method calculateFare(double distance)
    • Default: return 0
  2. Create subclasses:
    • MiniRide
    • LuxuryRide
  3. Override method:
    • MiniRide โ†’ โ‚น8 per km
    • LuxuryRide โ†’ โ‚น15 per km + โ‚น50 base charge
  4. In the main() method:
    • Take distance input
    • Use parent reference
    • Assign subclass objects
    • Display fare
  5. Output must show:
    • Ride type
    • Distance
    • Total fare

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

Q6. Exception Handling + Multiple Conditions

๐Ÿ“˜ Scenario: Age Verification System

๐Ÿ‘‰ Write a Java program to:

  1. Ask user to enter age
  2. Validate:
    • Age must be โ‰ฅ 18
  3. If:
    • Age < 18 โ†’ throw exception "Underage"
    • Age < 0 โ†’ throw exception "Invalid age"
  4. Use:
    • try-catch
    • Multiple conditions
  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 *