Created
November 22, 2014 22:06
-
-
Save rshepherd/fa4b641765906af8a583 to your computer and use it in GitHub Desktop.
Solution to practice midterm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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