β±οΈ 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:
- Create a class
MovieTicket. - Declare instance variables:
- movieName (String)
- showType (String) (βMorningβ or βEveningβ)
- numberOfTickets (int)
- pricePerTicket (double)
- Create a parameterized constructor:
- Initialize all variables using
this
- Initialize all variables using
- Create a method
calculateTotal():- Base total = numberOfTickets Γ pricePerTicket
- If showType = “Evening” β add 20% extra charge
- If numberOfTickets β₯ 5 β give 10% discount on final amount
- Create method
displayDetails():- Display all details including final amount
- 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:
- Create base class
Courier:- Method
calculateCost(double weight) - Default message:
Cost calculation not available
- Method
- Create subclasses:
DocumentCourierParcelCourier
- 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
- DocumentCourier:
- In the
main()method:- Take weight as input
- Create objects
- Display calculated cost
- 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:
- Create class
DigitalWallet. - Declare private variables:
- walletId (int)
- userName (String)
- balance (double)
- Provide getter and setter methods:
- Balance must not be negative
- Create methods:
addFunds(double amount)makePayment(double amount)
- Add conditions:
- Maximum payment allowed per transaction = βΉ5000
- Balance must remain β₯ βΉ200 after payment
- Otherwise display:
Transaction declined
- 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:
- Create an abstract class
UtilityBill:- Abstract method
calculateBill(int usage) - Concrete method
displayMessage()β prints"Bill Generated Successfully"
- Abstract method
- Create subclasses:
WaterBillInternetBill
- Implement method:
- WaterBill:
- βΉ2 per unit
- If usage > 100 β add βΉ50 extra
- InternetBill:
- βΉ500 fixed
- If usage > 500 β add βΉ100 extra
- WaterBill:
- In the
main()method:- Take usage input
- Call both methods
- 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:
- Create class
Insurance:- Method
calculatePremium(double amount) - Default: return 0
- Method
- Create subclasses:
HealthInsuranceVehicleInsurance
- Override method:
- HealthInsurance:
- Premium = 5% of amount
- If amount > 5,00,000 β add βΉ2000 extra
- VehicleInsurance:
- Premium = 3% of amount
- Minimum premium βΉ1000
- HealthInsurance:
- In the
main()method:- Take amount as input
- Use parent reference
- Display premium
- 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:
- Allow user to enter password
- Conditions:
- Correct password =
"admin123" - Maximum 3 attempts allowed
- Correct password =
- If:
- Wrong password β display
"Incorrect password" - After 3 attempts β throw exception
"Account Locked"
- Wrong password β display
- Use:
- Loop +
try-catch
- Loop +
- Finally block should print: