๐Ÿงพ Java OOP Practical Exam โ€“ Set 8 (Detailed & Student-Friendly)

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


๐Ÿ“Œ Instructions (Read Carefully):

  • Attempt all questions.
  • Write each program in a separate class/file.
  • Use proper OOP concepts and naming conventions.
  • Use Scanner class for user input wherever required.
  • Display output in a clear and labeled format.
  • Add comments to explain important parts of your code.

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


Q1. Class, Object & Constructor (10 Marks)

A gym management system needs to store and display details of members.

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

  1. Create a class named GymMember.
  2. Declare the following instance variables:
    • memberId (int)
    • memberName (String)
    • membershipType (String)
    • monthlyFee (double)
  3. Create a parameterized constructor:
    • It should accept values for all data members
    • Initialize them using the this keyword
  4. Create a method displayMemberDetails():
    • Display all member details in proper format
    • Example: Member ID: 1
      Name: Rahul
      Membership: Gold
      Monthly Fee: 2000.0
  5. In the main() method:
    • Ask the user to enter details for 2 members
    • Create objects using constructor
    • Display details of both members

Q2. Inheritance & Method Overriding (10 Marks)

A delivery company calculates shipping cost based on package type.

๐Ÿ‘‰ Write a Java program following these steps:

  1. Create a base class Shipment:
    • Method calculateCost(double weight)
    • Default message: "Cost calculation not defined"
  2. Create subclasses:
    • StandardShipment
    • ExpressShipment
  3. Override the method:
    • Standard โ†’ โ‚น20 per kg
    • Express โ†’ โ‚น40 per kg
  4. In the main() method:
    • Ask user to enter package weight
    • Create objects of both subclasses
    • Calculate and display cost
  5. Output must clearly show:
    • Shipment type
    • Weight
    • Total cost

Q3. Encapsulation (10 Marks)

An online wallet system needs to securely manage user balance.

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

  1. Create a class Wallet.
  2. Declare private variables:
    • walletId (int)
    • userName (String)
    • balance (double)
  3. Provide:
    • Getter and Setter methods
  4. Add validation:
    • Balance should not be negative
    • If invalid, display "Invalid balance amount"
  5. Create methods:
    • addMoney(double amount) โ†’ increase balance
    • spendMoney(double amount) โ†’ decrease balance if sufficient
  6. If balance is insufficient:
    • Display "Insufficient funds"
  7. In the main() method:
    • Create object
    • Set initial values
    • Perform add and spend operations
    • Display final wallet details

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


Q4. Interface (10 Marks)

A multimedia application plays different types of media files.

๐Ÿ‘‰ Write a Java program as follows:

  1. Create an interface MediaPlayer:
    • Method play()
    • Method stop()
  2. Implement the interface in:
    • AudioPlayer
    • VideoPlayer
  3. Define behavior:
    • Audio โ†’ "Playing audio" / "Stopping audio"
    • Video โ†’ "Playing video" / "Stopping video"
  4. In the main() method:
    • Use interface reference
    • Create objects of both classes
    • Call methods
  5. Ensure:
    • Proper interface implementation
    • Clear output messages

Q5. Runtime Polymorphism (10 Marks)

A billing system calculates discount based on customer type.

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

  1. Create a class Customer:
    • Method getDiscount(double amount)
    • Default: return 0
  2. Create subclasses:
    • RegularCustomer
    • PremiumCustomer
  3. Override method:
    • Regular โ†’ 5% discount
    • Premium โ†’ 15% discount
  4. In the main() method:
    • Use parent class reference
    • Assign subclass objects
    • Calculate and display final amount
  5. Output must show:
    • Customer type
    • Original amount
    • Discount applied
    • Final amount

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

Q6. Exception Handling with Validation

๐Ÿ‘‰ Write a Java program to:

  1. Ask user to enter:
    • Age
  2. Validate:
    • Age must be greater than 0
  3. If invalid:
    • Throw exception and display "Invalid age entered"
  4. Use:
    • try-catch
    • throw keyword
  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 *