summaryrefslogtreecommitdiff
path: root/oop/04-encapsulation/Account.java
blob: 55d99d0d61a4fc877577fe600bab43155a14afc7 (plain)
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
public class Account {
	
	/* Declaring fields  - represent state */
	
	private int accountNumber;
	private double balance;
	
	
	/* Declaring methods - represent operations */
	
	public void withdraw(double amount) {
		if (balance >= amount) {
			balance = balance - amount;
		}
	}

	public void deposit(double amount) {
		balance += amount;
	}
	
	public double getBalance() {
		return balance;
	}
	
	public void setBalance(double newBalance) {
		balance = newBalance;
	}
}