Skip to content

Instantly share code, notes, and snippets.

@rshepherd
Created November 22, 2014 22:06
Show Gist options
  • Save rshepherd/fa4b641765906af8a583 to your computer and use it in GitHub Desktop.
Save rshepherd/fa4b641765906af8a583 to your computer and use it in GitHub Desktop.
Solution to practice midterm
public class TestDigitalWallet {
public static void main(String[] args) {
DigitalWallet w1 = new DigitalWallet(1);
w1.deposit(10000);
w1.withdraw(5000);
DigitalWallet.setMaxWithdrawalPct(.75);
System.out.println(w1.canWithdraw(4000)); // false
DigitalWallet w2 = new DigitalWallet(2, 20000);
w2.withdraw(5000);
w2.withdraw(5000);
long[] txs = w2.getTransactionHistory().getTransactions();
int sum = 0;
for(int i = 0; i < txs.length ; ++i) {
sum += txs[i];
}
if(sum == w2.getBalance()) {
System.out.println("Balance equals sum of transactions.");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment