0% found this document useful (0 votes)
71 views

OOP Assignment 6

Uploaded by

Abdullah Afzal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views

OOP Assignment 6

Uploaded by

Abdullah Afzal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

TASK # 1:

Scenario: You are tasked with developing a banking application that


performs various operations like deposits, withdrawals, and balance
inquiries. The application needs to handle invalid input and runtime errors
effectively, such as attempting to withdraw more money than available.

Task Description:

• Create a class BankAccount with methods for deposit(double


amount) and withdraw(double amount).

• Implement exception handling to manage:

– IllegalArgumentException for negative deposit/withdrawal


amounts.

– InsufficientFundsException for withdrawals that exceed the


current balance.

• Write a main method to simulate user interactions, capturing any


exceptions thrown and displaying appropriate error messages.

TASK #2

A software company is developing an Online Payment System that


supports multiple payment methods like Credit Card, PayPal, and Bank
Transfer. They want to ensure that the system handles payment failures
smoothly, allowing the user to retry or select a different method without
the program crashing.

The company has created an interface called PaymentMethod, which


includes a method processPayment(double amount) that each payment
class (CreditCard, PayPal, BankTransfer) must implement. During the
payment process, certain exceptions can occur, such as:

• InvalidCardException: Raised if the user inputs an invalid credit card


number.

• InsufficientFundsException: Raised if the user's bank account or


PayPal balance has insufficient funds.

• PaymentNetworkException: Raised if there is a network issue while


processing the payment.

Your task:

i. Define the PaymentMethBankTransfer—that implement


PaymentMethod and throw the appropriate exception of interface
with the method processPayment(double amount) that throws the
potential exceptions.
ii. Create three classes—CreditCard, PayPal, and s based on the
following scenarios:

 CreditCard: Throws an InvalidCardException if the card number


is invalid.

 PayPal: Throws an InsufficientFundsException if the PayPal


balance is too low.

 BankTransfer: Throws a PaymentNetworkException if a network


issue occurs.

iii. In the main class, simulate the payment process by allowing the user
to choose a payment method and handle the exceptions gracefully
using try-catch blocks, prompting the user to retry if an exception is
thrown.

Task Description:

The task involves developing an Online Payment System with multiple


payment methods: Credit Card, PayPal, and Bank Transfer. Each payment
method implements a common PaymentMethod interface with the method
processPayment(double amount).

During the payment process, specific exceptions can occur:

 InvalidCardException for invalid credit card numbers.

 InsufficientFundsException for insufficient funds in PayPal or


bank accounts.

 PaymentNetworkException for network issues during a bank


transfer.

The system must handle these exceptions gracefully, allowing users to


retry or choose a different payment method without crashing. The main
class will simulate the payment process and manage errors using try-catch
blocks.

TASK #3

Scenario: In a transportation system, you need to manage various modes


of transport like cars, bikes, and trucks. Each mode of transport has
specific capabilities but should also adhere to common transportation
functionalities.

Task Description:

i. Create a package named Transport to contain all transport-related


classes.

ii. Define two interfaces: Drivable with methods such as drive() and
stop(), and Loadable with methods such as loadCargo(int weight)
and unloadCargo().
iii. Implement classes Car, Bike, and Truck that implement the Drivable
interface. The Truck class should also implement the Loadable
interface. Each class should define its unique attributes and methods
while adhering to the interface contracts.

iv. Create main class in package mainpkg and implement all classes in
main class.

v. Show the result.

You might also like