Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the following class, representing a BankAccount and its transaction his

ID: 3595590 • Letter: C

Question

Consider the following class, representing a BankAccount and its transaction history.

public class Account {

public Account(long num) {
    id = num;
    balance = 0.0;
    transactions = new ArrayList<Double>();
}

public void deposit(Double d) {
    transactions.add(d);
    balance = balance + d;
}

public void withdraw(Double d) {
    transactions.add(-d);
    balance = balance - d;
}

public Double getBalance() {
    return balance;
}

public ArrayList<Double> getTransactionHistory() {
    return transactions;
}

public long id;
private Double balance;
private ArrayList<Double> transactions;
}

1.Which of its methods are accessors? Which of its methods are mutators?

2. What do you like about the class design?

e. The class is immutable

3. What do you dislike about the class design?

a. It clearly distinguishes between mutator and accessor methods

Explanation / Answer

1. getBalance() and getTransactionHistory() methods are accessors. deposit() and withdraw() methods are mutators

2. The data is encapsulated (b)

3. Returning the arrayList breaks the encapsulation (d)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote