-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankApp.java
More file actions
41 lines (40 loc) · 1.08 KB
/
BankApp.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
package com.sarvesh.javabasics;
public class BankApp {
static class BankAccount {
private String name;
private double balance;
// setter
public void setName(String name) {
this.name = name;
}
// getter
public String getName() {
return name;
}
// deposit
public void deposit(double amount) {
if(amount > 0) {
balance += amount;
}
}
// withdraw
public void withdraw(double amount) {
if(amount > 0 && amount <= balance) {
balance -= amount;
} else {
System.out.println("Invalid transaction");
}
}
public void display() {
System.out.println("Name: " + name);
System.out.println("Balance: " + balance);
}
}
public static void main(String[] args) {
BankAccount acc = new BankAccount();
acc.setName("Sarvesh");
acc.deposit(1000);
acc.withdraw(300);
acc.display();
}
}