-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathReusing_Classes_4.java
More file actions
54 lines (38 loc) · 1.06 KB
/
Reusing_Classes_4.java
File metadata and controls
54 lines (38 loc) · 1.06 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
54
package armstrong.alexandra;
/**
* Created by alexandraarmstrong on 1/18/17.
*/
public class Reusing_Classes_4 {
public static void main(String[] args){
CheckingAccount ca = new CheckingAccount();
SavingsAccount sa = new SavingsAccount();
BusinessAccount ba = new BusinessAccount();
ca.credit(126);
ca.debit(43);
ba.credit(65);
ba.debit(10);
sa.credit(9384);
sa.debit(45);
System.out.println("Business Account balance " + ba.getBalance());
System.out.println("Savings Account balance " + sa.getBalance());
System.out.println("Checking Account balance " + ca.getBalance());
}
}
abstract class BankAccount{
double balance;
public double getBalance() {
return balance;
}
public void debit(double amount) {
balance -= amount;
}
public void credit(double amount) {
balance += amount;
}
}
class CheckingAccount extends BankAccount{
}
class SavingsAccount extends BankAccount{
}
class BusinessAccount extends BankAccount{
}