- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankApp.java
More file actions
Latest commit
41 lines (40 loc) · 1.08 KB
/
Copy pathBankApp.java
File metadata and controls
41 lines (40 loc) · 1.08 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
packagecom.sarvesh.javabasics;
publicclassBankApp {
staticclassBankAccount {
privateStringname;
privatedoublebalance;
// setter
publicvoidsetName(Stringname) {
this.name = name;
}
// getter
publicStringgetName() {
returnname;
}
// deposit
publicvoiddeposit(doubleamount) {
if(amount > 0) {
balance += amount;
}
}
// withdraw
publicvoidwithdraw(doubleamount) {
if(amount > 0 && amount <= balance) {
balance -= amount;
} else {
System.out.println("Invalid transaction");
}
}
publicvoiddisplay() {
System.out.println("Name: " + name);
System.out.println("Balance: " + balance);
}
}
publicstaticvoidmain(String[] args) {
BankAccountacc = newBankAccount();
acc.setName("Sarvesh");
acc.deposit(1000);
acc.withdraw(300);
acc.display();
}
}