PSOOPL - Experiment 9-2
PSOOPL - Experiment 9-2
UID: 2024300019
Experiment No. 9
Program 1
● Name
● Balance
● Acc_No
Method:-
Saving Account inherits the Account class and provides the implementation
for the methods accordingly
● interestRate
● minBalance
Method
● transfer():
Note:
● let the user deposit to or withdraw from the account. For each
reason is reported.
For the above scenario write an interactive program in Java. Also, show
output for different use cases.
@Override
void deposit(double amount) throws NegativeAmountException {
if (amount < 0)
throw new NegativeAmountException("Deposit failed: Amount
cannot be negative.");
balance += amount;
System.out.println("Deposit successful. Current Balance: " +
balance);
}
@Override
void withdraw(double amount) throws NegativeAmountException,
InsufficientAmountException {
if (amount < 0)
throw new NegativeAmountException("Withdraw failed:
Amount cannot be negative.");
if (balance - amount < minBalance)
throw new InsufficientAmountException("Withdraw failed:
Balance would go below minimum allowed (" + minBalance + ")");
balance -= amount;
System.out.println("Withdraw successful. Current Balance: " +
balance);
}
@Override
void display() {
System.out.println("Account No: " + accNo);
System.out.println("Name: " + name);
System.out.println("Balance: " + balance);
System.out.println("Interest Rate: " + interestRate);
System.out.println("Minimum Balance: " + minBalance);
}
}
class BankSystem {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
sc.close();
}
}
RESULT:
CONCLUSION: