import tester.Tester; //Used with the tester. public class Examples { /* * In Java, we can define class wide variables * by placing them outside of a method. If we placed * the variables inside the constructor (as we have * done in the past with Examples), we would have * no access them in other methods because of how * "Scoping" works. */ //Checking template // accountNum ... int // balance ... int // name ... String // minimum ... int Checking check1; Checking check2; Checking check3; //Savings Template // accountNum ... int // balance ... int // name ... String // interest ... double Savings savings1; Savings savings2; Savings savings3; //Empty constructor. public Examples(){ } //Initializes some accounts to use for testing. //We place inside init() so we can "reuse" the accounts public void init(){ //Initialize the checking accounts. check1 = new Checking(0001, 0, "First Checking Account", 0); check2 = new Checking(0002, 100, "Second Checking Account", 50); check3 = new Checking(0003, 500, "Third Checking Account", 0); //Initialize the savings accounts. savings1 = new Savings(0004, 0, "First Savings Account", 4.9); savings2 = new Savings(0005, 100, "Second Savings Account", 8.9); savings3 = new Savings(0006, 0, "Third Savings Account", 1.1); } //Tests the exceptions we expect to be thrown when //performing an "illegal" action. public void testExceptions(Tester t){ init(); Object[] args = new Object[1]; args[0] = 100; t.checkExpect( check1, "withdraw", args, new RuntimeException("Insufficient Funds for " + check1.name), "The test should pass, we supplied the right information" ); t.checkExpect( savings1, "withdraw", args, new RuntimeException("Insufficient Funds for " + savings1.name), "The test should pass, we supplied the right information" ); } //Tests the deposit methods inside certain accounts. public void testDeposit(Tester t){ init(); t.checkExpect(check1.deposit(100), 100); t.checkExpect(check2.deposit(500), 600); t.checkExpect(savings1.deposit(100), 100); t.checkExpect(savings2.deposit(100), 200); } //Tests the withdraw methods inside certain accounts. public void testWithdraw(Tester t){ init(); t.checkExpect(check2.withdraw(49), 51); t.checkExpect(savings2.withdraw(100), 0); } }