-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTuto1Q5.java
More file actions
53 lines (45 loc) · 1.18 KB
/
Copy pathTuto1Q5.java
File metadata and controls
53 lines (45 loc) · 1.18 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
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package Week1;
/**
*
* @author szeyu
*/
interface Account{
public int deposit(int amount);
public boolean withdraw(int amount);
}
class BankAccount implements Account{
private int balance;
public BankAccount(int balance) {
this.balance = balance;
}
public int deposit(int amount){
balance += amount;
return balance;
}
public boolean withdraw(int amount){
if(amount > balance){
return false;
}
balance -= amount;
return true;
}
public String toString(){
return "Balance: " + balance;
}
}
public class Tuto1Q5 {
public static void main(String[] args) {
BankAccount account1 = new BankAccount(100);
System.out.println(account1);
account1.deposit(100);
System.out.println(account1);
account1.withdraw(50);
System.out.println(account1);
account1.withdraw(200);
System.out.println(account1);
}
}