

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
Material Type: Assignment; Class: Full Course Title: Program Design and Development; Subject: COMPUTER SCIENCE; University: University of Arizona; Term: Spring 2008;
Typology: Assignments
1 / 3
This page cannot be seen from the preview
Don't miss anything!


@Test public void testBalanceAtInitialization() { ArrayPiggyBank aBank = new ArrayPiggyBank(); assertEquals(0.0, aBank.getTotal(), 0.001); ArrayPiggyBank anotherBank = new ArrayPiggyBank(); assertEquals(0.0, anotherBank.getTotal(), 0.001); } @Test public void testAddPennies() { ArrayPiggyBank aBank = new ArrayPiggyBank(); aBank.addPennies(1); assertEquals(0.01, aBank.getTotal(), 0.001); aBank.addPennies(3); assertEquals(0.04, aBank.getTotal(), 0.001); } @Test public void testAddNickels() { ArrayPiggyBank aBank = new ArrayPiggyBank(); aBank.addNickels(2); assertEquals(0.10, aBank.getTotal(), 0.001); aBank.addNickels(20); assertEquals(1.10, aBank.getTotal(), 0.001); } @Test public void testToString() { ArrayPiggyBank aBank = new ArrayPiggyBank(); assertEquals("Coins were entered in this order: ", aBank.toString()); aBank.addPennies(2); aBank.addNickels(2); assertEquals("Coins were entered in this order: 1 1 5 5 ", aBank.toString()); aBank.addPennies(1); aBank.addNickels(1); aBank.addPennies(3); aBank.addNickels(1); assertEquals("Coins were entered in this order: 1 1 5 5 1 5 1 1 1 5 ", aBank.toString()); }
public class ArrayPiggyBank { private int[] coins; private int n; // Construct a PiggyBank with no money that can store up to 1000 pennies and nickels public ArrayPiggyBank() { } // Return the amount of money in this PiggyBank as a dollars and cents // amount. After construction, getTotal() must return 0. public double getTotal() { } // Add the given number of pennies to this PiggyBank public void addPennies(int pennies) { } // Add the given number of nickels this PiggyBank public void addNickels(int nickels) { } // Return a string all coins, pennies are 1, nickels are 5. For example: // aBank.addPennies(1); // aBank.addNickels(1); // assertEquals("Coins were entered in this order: 1 5 ", aBank.toString()); public String toString() { String result = "Coins were entered in this order: ";