โฑ๏ธ 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:
- Create a class named
FoodItem. - Declare the following data members:
- itemId (int)
- itemName (String)
- price (double)
- quantity (int)
- Create a parameterized constructor:
- Initialize all data members using
thiskeyword
- Initialize all data members using
- Create a method
calculateTotal():- Calculate total price = price ร quantity
- Return total
- Create a method
displayDetails():- Display all details including total price
- 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:
- Create a base class
Employee:- Variable: name
- Method
calculateBonus()โ default message
- Create subclasses:
ManagerClerk
- Override method:
- Manager โ Bonus = โน8000
- Clerk โ Bonus = โน3000
- In
main():- Create objects of both classes
- Call method and display bonus
- 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:
- Create a class
ATMAccount. - Declare private variables:
- accountNumber (int)
- accountHolder (String)
- balance (double)
- Provide:
- Getter and Setter methods
- Add validation:
- Balance cannot be negative
- Create methods:
deposit(double amount)withdraw(double amount)
- Conditions:
- Withdrawal allowed only if sufficient balance
- Otherwise print
"Transaction failed: insufficient balance"
- 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:
- Create an abstract class
VehicleService:- Abstract method
calculateServiceCharge()
- Abstract method
- Create subclasses:
CarServiceBikeService
- Implement method:
- Car โ โน2000
- Bike โ โน800
- In
main():- Use abstract class reference
- Create objects of subclasses
- Display service charges
- 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:
- Create a class
Subscription:- Method
getMonthlyCost() - Default: return 0
- Method
- Create subclasses:
BasicPlanPremiumPlan
- Override method:
- Basic โ โน199/month
- Premium โ โน499/month
- In
main():- Use parent class reference
- Assign objects of subclasses
- Display cost
- 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:
- Ask user to enter:
- Username
- Password
- Validate:
- If username โ “admin” OR password โ “1234”
- Throw a custom exception
"Invalid Login"
- Use:
try-catch- Custom exception class
- Finally block should print:
Login attempt finished