0% found this document useful (0 votes)
3 views3 pages

Print Out PDF

The document contains a Java class named AbdulRahmanBank that manages a bank account with methods for depositing and withdrawing funds. It includes error handling for invalid deposit and withdrawal amounts, throwing exceptions with specific messages. The main method demonstrates the functionality of the class with a sample account balance and transactions.

Uploaded by

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

Print Out PDF

The document contains a Java class named AbdulRahmanBank that manages a bank account with methods for depositing and withdrawing funds. It includes error handling for invalid deposit and withdrawal amounts, throwing exceptions with specific messages. The main method demonstrates the functionality of the class with a sample account balance and transactions.

Uploaded by

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

class AbdulRahma

No category Today 8:46 PM

class AbdulRahmanBank {
private double balance;

public AbdulRahmanBank(double
initialBalance) {
this.balance = initialBalance;
}

public void deposit(double amount) {


if (amount < 0) {
throw new
IllegalArgumentException("Abdul Rahman,
Account Number: 123456, Deposit amount
must be positive.");
}
this.balance += amount;
System.out.println("Deposit
successful. New balance: " + this.balance);
}

public void withdraw(double amount) {


if (amount < 0 || amount > this.balance)
{
throw new
IllegalArgumentException("Abdul Rahman,
Account Number: 123456, Withdrawal
amount is invalid.");
}
this.balance -= amount;
System.out.println("Withdrawal
successful. New balance: " + this.balance);
}
public static void main(String[] args) {
AbdulRahmanBank abdulRahmanBank
= new AbdulRahmanBank(1000);

try {
abdulRahmanBank.deposit(500);
abdulRahmanBank.withdraw(200);

abdulRahmanBank.withdraw(2000); // This
will throw an exception
} catch (IllegalArgumentException e) {
System.out.println(e.getMessage());
}
}
}

You might also like