summaryrefslogtreecommitdiff
path: root/oop/05-destructor/Account.java
blob: a5baab738d3575bd23a33da3495b589c5cb00415 (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
30
31
32
33
public class Account {
	
	/* Declaring fields  - represent state */
	
	int accountNumber;
	double balance;
	
	/* Declaring methods - represent operations */

	/*
	 * Here is a useless destructor just for testing.
	 */
	public void finalize() {
		System.out.println("Object is being descarded");
		System.exit(0);
	}
	
	public void withdraw(double amount) {
		if (balance >= amount) {
			balance = balance - amount;
		}
	}

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