

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
We've created a BankAccount class that (as the name suggests) represents a bank account. For our program, the BankAccount class must meet several ...
Typology: Study notes
1 / 2
This page cannot be seen from the preview
Don't miss anything!


Using JUnit Lesson: Bank Account Java Class 1
public class BankAccount { public BankAccount(int acctNum) { this.acctNum = acctNum; } private int getAccountNum() { return acctNum; } private boolean deposit(int amount) { if (amount <= 0) return false; balance += amount; lastTransaction = amount; return true; } private boolean withdraw(int amount) { if (amount > 0 && balance >= amount) { balance -= amount; lastTransaction = -amount; return true; }
Using JUnit Lesson: Bank Account Java Class 2 else return false; } private int getBalance() { return balance; } private int getLastTransAmount() { return lastTransaction; } @Override public String toString() { return String.format("Account %d (balance $%d)", acctNum, balance); } private int acctNum; private int balance; private int lastTransaction; }