Below are two classes. One defines a PiggyBank class, and the other class is a tester. Copy the two classes into BlueJ.
/*******************************************************
* >>>>>>>>>>>>>>> PiggyBank Class <<<<<<<<<<<<<<<<
* Computes the total value of a collection of coins.
********************************************************/
public class PiggyBank
{
private static final double NICKEL_VALUE = 0.05;
private static final double DIME_VALUE = 0.1;
private static final double QUARTER_VALUE = 0.25;
private int nickels;
private int dimes;
private int quarters;
/**
* Constructs an empty PiggyBank.
*/
public PiggyBank()
{
nickels = 0;
dimes = 0;
quarters = 0;
}
/**
* Add nickels
* @param count the number of nickels to add
*/
public void addNickels(int count)
{
// >>> complete the code to add to nickels <<<
}
/**
* Add dimes
* @param count the number of dimes to add
*/
public void addDimes(int count)
{
// >>> complete the code to add to dimes <<<
}
/**
* Add quarters
* @param count the number of quarters to add
*/
public void addQuarters(int count)
{
// >>> complete the code to add to quarters <<<
}
/**
* Get the total value of the coins in the purse.
* @return the sum of all coin values
*/
public double getTotal()
{
// >>> complete the code: returns the total value of the piggy bank <<<
}
}
/******************************************************
** >>>>>>>>> PiggyBankTester <<<<<<<<<<<
*******************************************************/
import java.util.*;
public class PiggyBankTester
{
public static void main(String[] args)
{
PiggyBank myBank = new PiggyBank();
myBank.addNickels(5);
myBank.addDimes(3);
myBank.addQuarters(2);
double totalValue = myBank.getTotal();
System.out.println("The total is " + totalValue);
}
}