-
Notifications
You must be signed in to change notification settings - Fork 0
/
SavingsAccount.java
44 lines (39 loc) · 975 Bytes
/
SavingsAccount.java
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
public class SavingsAccount {
// Properties of the class..
private int balance;
// Constructor of the class..
public SavingsAccount() {
balance = 0;
}
public SavingsAccount(int initialBalance) {
balance = initialBalance;
}
// Methods of the class...
public void greet() {
System.out.println("Hello valued customer");
}
public int showBalance() {
return balance;
}
// Main Method
public void main deposit(int howMuch) {
if (howMuch < 0) {
System.out.println("You can’t deposit a negative amount!");
}
else {
balance = balance + howMuch;
}
}
public void withdraw(int howMuch) {
if (howMuch < 0) {
System.out.println("You can’t withdraw a negative amount!");
}
else {
balance = balance - howMuch;
}
}
public void transfer(SavingsAccount whereTo, int howMuch) {
balance = balance - howMuch;
whereTo.balance = whereTo.balance + howMuch;
}
}