-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcasffe.java
More file actions
53 lines (41 loc) · 1.36 KB
/
casffe.java
File metadata and controls
53 lines (41 loc) · 1.36 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
class Main {
static class InsufficientFundsError extends Exception {
public InsufficientFundsError(String message) {
super(message);
}
}
static class BankAccount {
private static int accCounter = 100;
private int accNumber;
private String name;
private double balance;
public BankAccount(String name, double balance) {
accCounter++;
this.accNumber = accCounter;
this.name = name;
this.balance = balance;
}
public void deposit(double amount) {
balance += amount;
}
public void withdraw(double amount) throws InsufficientFundsError {
if (amount > 0 && amount <= balance) {
balance -= amount;
} else {
throw new InsufficientFundsError("Not Enough Funds you rookie");
}
}
public double getBalance() {
return balance;
}
public String details() {
return accNumber + ", " + name + ", " + balance;
}
}
public static void main(String[] args) {
BankAccount harshith = new BankAccount("Harshith", 100000);
BankAccount reddy = new BankAccount("Reddy", 1000055555);
System.out.println(harshith.details());
System.out.println(reddy.details());
}
}