introduction to java chapter number 9 exercise number 9 7 solution

Solutions on MaxInterview for introduction to java chapter number 9 exercise number 9 7 solution by the best coders in the world

showing results for - "introduction to java chapter number 9 exercise number 9 7 solution"
Aurélien
24 Feb 2018
1import java.util.ArrayList;
2import java.util.Date;
3
4public class Account {
5
6    protected String mName;
7    protected int mId;
8    protected double mBalance;
9    protected double mAnnualInterestRate; // AnnualInterestRate is percentage.
10    protected Date mDateCreated;
11    protected ArrayList<Transaction> mTransactions;
12
13
14    public Account() {
15        mDateCreated = new Date();
16        mTransactions = new ArrayList<>();
17    }
18
19    public Account(int id, double balance) {
20        this();
21        mId = id;
22        mBalance = balance;
23    }
24
25    public Account(String name, int id, double balance) {
26        this(id, balance);
27        mName = name;
28
29    }
30
31    public int getId() {
32        return mId;
33    }
34
35    public void setId(int id) {
36        mId = id;
37    }
38
39    public double getBalance() {
40        return mBalance;
41    }
42
43    public void setBalance(double balance) {
44        mBalance = balance;
45    }
46
47    public double getAnnualInterestRate() {
48        return mAnnualInterestRate;
49    }
50
51    public void setAnnualInterestRate(double annualInterestRate) {
52        mAnnualInterestRate = annualInterestRate;
53    }
54
55    public Date getDateCreated() {
56        return mDateCreated;
57    }
58
59    public double getMonthlyInterestRate() {
60        return mBalance * (mAnnualInterestRate / 12) / 100;
61    }
62
63    public void withdraw(double amount) {
64        mTransactions.add(new Transaction('W', amount, mBalance, "withdraw"));
65        mBalance -= amount;
66    }
67
68    public void deposit(double amount) {
69        mTransactions.add(new Transaction('D', amount, mBalance, "deposit"));
70        mBalance += amount;
71    }
72
73    @Override
74    public String toString() {
75        return "Account name: " + mName + "\n" + "Interest rate: " + mAnnualInterestRate + "\n" + mTransactions;
76    }
77
78    public ArrayList<Transaction> getTransactions() {
79        return new ArrayList<>(mTransactions);
80    }
81
82}
83