๐Ÿงพ Java OOP Practical Exam โ€“ Set 9 (Case-Study Based & Detailed)

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


๐Ÿ“Œ Instructions (Read Carefully):

  • Attempt all questions.
  • Each question must be implemented using separate classes.
  • Follow proper OOP design (class, methods, inheritance, etc.).
  • Use Scanner class for user input wherever mentioned.
  • Display output clearly with proper labels.
  • Write comments to explain your logic.

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


Q1. Class, Object & Constructor (10 Marks)

๐Ÿ“˜ Case Study: Online Food Ordering System

A food ordering platform wants to manage food item details and calculate total bill.

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

  1. Create a class named FoodItem.
  2. Declare the following data members:
    • itemId (int)
    • itemName (String)
    • price (double)
    • quantity (int)
  3. Create a parameterized constructor:
    • Initialize all data members using this keyword
  4. Create a method calculateTotal():
    • Calculate total price = price ร— quantity
    • Return total
  5. Create a method displayDetails():
    • Display all details including total price
  6. In the main() method:
    • Ask user to enter details of 2 food items
    • Create objects
    • Display bill for each item

Q2. Inheritance & Method Overriding (10 Marks)

๐Ÿ“˜ Case Study: Employee Bonus System

A company gives bonus based on employee role.

๐Ÿ‘‰ Write a Java program as follows:

  1. Create a base class Employee:
    • Variable: name
    • Method calculateBonus() โ†’ default message
  2. Create subclasses:
    • Manager
    • Clerk
  3. Override method:
    • Manager โ†’ Bonus = โ‚น8000
    • Clerk โ†’ Bonus = โ‚น3000
  4. In main():
    • Create objects of both classes
    • Call method and display bonus
  5. Output should clearly indicate:
    • Employee type
    • Bonus amount

Q3. Encapsulation (10 Marks)

๐Ÿ“˜ Case Study: ATM System

An ATM system needs secure handling of account balance.

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

  1. Create a class ATMAccount.
  2. Declare private variables:
    • accountNumber (int)
    • accountHolder (String)
    • balance (double)
  3. Provide:
    • Getter and Setter methods
  4. Add validation:
    • Balance cannot be negative
  5. Create methods:
    • deposit(double amount)
    • withdraw(double amount)
  6. Conditions:
    • Withdrawal allowed only if sufficient balance
    • Otherwise print "Transaction failed: insufficient balance"
  7. In main():
    • Create object
    • Perform deposit and withdrawal
    • Display final balance

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


Q4. Abstract Class (10 Marks)

๐Ÿ“˜ Case Study: Vehicle Service System

Different vehicles have different service charges.

๐Ÿ‘‰ Write a Java program as follows:

  1. Create an abstract classVehicleService:
    • Abstract method calculateServiceCharge()
  2. Create subclasses:
    • CarService
    • BikeService
  3. Implement method:
    • Car โ†’ โ‚น2000
    • Bike โ†’ โ‚น800
  4. In main():
    • Use abstract class reference
    • Create objects of subclasses
    • Display service charges
  5. Output should clearly show:
    • Vehicle type
    • Service charge

Q5. Runtime Polymorphism (10 Marks)

๐Ÿ“˜ Case Study: Online Subscription System

Different subscription plans have different monthly costs.

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

  1. Create a class Subscription:
    • Method getMonthlyCost()
    • Default: return 0
  2. Create subclasses:
    • BasicPlan
    • PremiumPlan
  3. Override method:
    • Basic โ†’ โ‚น199/month
    • Premium โ†’ โ‚น499/month
  4. In main():
    • Use parent class reference
    • Assign objects of subclasses
    • Display cost
  5. Clearly demonstrate:
    • Runtime polymorphism
    • Same method behaving differently

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

Q6. Custom Exception Handling

๐Ÿ“˜ Case Study: Login System

๐Ÿ‘‰ Write a Java program to:

  1. Ask user to enter:
    • Username
    • Password
  2. Validate:
    • If username โ‰  “admin” OR password โ‰  “1234”
    • Throw a custom exception "Invalid Login"
  3. Use:
    • try-catch
    • Custom exception class
  4. Finally block should print: Login attempt finished

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 *