







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!








Goals
Four Classes
extends TestCase, many methods to help with testing are available. In this project, you will only need these assertions:
public static void assertEquals (String expected, String actual)
public static void assertEquals (int expected, int actual)
public static void assertEquals (double expected, double actual, double tolerance)
public static void assertTrue (boolean condition)
public static void assertFalse (boolean condition)
1. Implement Song using Test Driven Development
First consider the two classes that you are about to write are part of a bigger system described below. Here is an overview of a Cashless Jukebox System: The following design shows that JukeboxAccount has a dependency on Song. The arrow with dotted line states "JukeboxAccount needs Song". So you will be asked to test and build the Song class first. Note: the + means public—the return types and parameters are not sow here. Each Song object knows its title and its length in playtime (seconds). JukeboxAccount object will know the name of its human equivalent and how much time the user has remaining to play songs. Anyone can ask the JukeboxAccount if it can play a Song. This canSelect message to a JukeboxAccout will return true if the JukeboxAccount has enough time to play the given Song.
// Construct a new JukeboxAccount object, using the initial // state supplied by the arguments. Parameters: // ID: The identification string associate with this user // secondsOfPlayTime: How many seconds this user has left to play Songs public JukeboxAccount(String ID, int secondsOfPlayTime) // Provide access to this JukeboxAccount's ID string so // you can find this JukeBoxAccount in a collection public String getID() // Reduce this JukeboxAccount's time credit by the playtime of theSong public void debit(Song theSong)
// Provide access to how much playtime this user has remaining. // Returns the number of seconds of time credit for this user public int getSecondsRemaining() // Let the sender know if the current user can play a specific Song. // Note: The user can have the Song played if this JukeboxAccount has // as much time remaining as the time it takes to play theSong // Parameter: theSong is the Song (with playtime) to be played. // Return true if the JukeboxAccount has enough time credit. public boolean canSelect(Song theSong) 2b Optional. Download the Unit test JukeBoxAccountGradingTest.java to make sure all of our assertions will pass.
3. Implement class PiggyBank using TDD Implement class PiggyBank, an object to which pennies, nickels and dimes can be added. Each PiggyBank object keeps track of how much money is in the PiggyBank. A PiggyBank can be raided anytime to reduce the total amount of money to 0.00. Make sure you include a unit test named PiggyBankTest that tests all methods. // Construct a piggy bank with a name but no money public PiggyBank ( String piggyBankName) // Return the name of this PiggyBank public String getName() // Return the amount of money in this PiggyBank as a dollars and cents // amount. After construction or a jiggle, getTotal() must return 0. public double getTotal() // Simulate a complete raid on this piggy bank. After a jiggle // message, this PiggyBank object has no money remaining. public void jiggle() // Add the given number of pennies to this PiggyBank public void addPennies(int penniesToAdd) // Add the given number of mickles this PiggyBank public void addNickels(int nickelsToAdd); // Add the given number of dimes to this PiggyBank public void addDimes(int dimesToAdd) // Add the given number of quarters to this PiggyBank public void addQuarters(int quartersToAdd)
Run a GUI that will use your WeeklyEmployee class Once you have finished the WeeklyEmployee class, see your solution in action with a graphical user interface. First copy and paste the code from these two files into the correctly named files in your project: