-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMiniBank.java
More file actions
25 lines (21 loc) · 761 Bytes
/
Copy pathMiniBank.java
File metadata and controls
25 lines (21 loc) · 761 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import java.util.Scanner;
public class MiniBank {
public static void main(String[] args) {
double balance = 500.0;
Scanner sc = new Scanner(System.in);
try {
System.out.print("Enter amount to withdraw: ");
double amount = sc.nextDouble();
if (amount > balance) {
throw new Exception("Insufficient balance!");
}
balance -= amount;
System.out.println("Withdrawal successful. Remaining balance: $" + balance);
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
} finally {
System.out.println("Transaction complete.");
sc.close();
}
}
}