In Class Activity - Program Design and Development - Fall 2008 | C SC 227, Assignments of Computer Science

Material Type: Assignment; Class: Full Course Title: Program Design and Development; Subject: COMPUTER SCIENCE; University: University of Arizona; Term: Spring 2008;

Typology: Assignments

Pre 2010

Uploaded on 08/31/2009

koofers-user-7yn
koofers-user-7yn 🇺🇸

5

(1)

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
C Sc 227 In-Class Activity, Friday 8-Feb-08
Form a team of 2 and print you names neatly here:
o ______________________________ o _________________________________
Choose the scribe as the person who has the most aunts and uncles and circle the
scribe's section leader:
Dave Eric Mark Zack
On the back of this page, complete class PiggyBank to remember how pennies and nickels
were entered and how much money is in the PiggyBank. These assertions must pass
@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());
}
pf3

Partial preview of the text

Download In Class Activity - Program Design and Development - Fall 2008 | C SC 227 and more Assignments Computer Science in PDF only on Docsity!

C Sc 227 In-Class Activity, Friday 8-Feb-

Form a team of 2 and print you names neatly here:

o ______________________________ o _________________________________

Choose the scribe as the person who has the most aunts and uncles and circle the

scribe's section leader:

Dave Eric Mark Zack

On the back of this page, complete class PiggyBank to remember how pennies and nickels

were entered and how much money is in the PiggyBank. These assertions must pass

@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: ";