โฑ๏ธ 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: