The error that the online tester for this project gave me was:
"Test results indicate that your code still contains bugs. Your code appears to cover only 56% of the behavior required for this assignment.
Double check that you have carefully followed all initial conditions requested in the assignment in setting up your solution, and that you have also met all requirements for a complete solution in the final state of your program.
The following hint(s) may help you locate some ways in which your solution may be improved:
*
sell ice cream
*
multi sell I ice cream
*
sell ice cream no ice cream
(only 3 of 4 hints shown)"
I think I set all the initial conditions correctly. In anycase, I don't know what's wrong. This is my whole program:
Expand|Select|Wrap|Line Numbers
- public class IceCreamStation
- {
- /** instance variables.*/
- /**amount of cash in station.*/
- private double numCash;
- /**number of cones.*/
- public int numCones;
- /**amount of cash used to buy cones.*/
- public double cashBuyCones;
- /**amount of cash used to buy ice cream.*/
- public double cashBuyIceCream;
- /**number of cones sold.*/
- public int numSold;
- /**amount of ice cream in pints.*/
- public double numIceCream;
- /**price per pint of ice cream.*/
- public static final double PRICEPERPINT = 3.25;
- /**price per pint box of cones.*/
- public static final double PRICEPERBOX = 2.50;
- /**amount of cones in box.*/
- public static final int CONESPERBOX = 10;
- /**amount of pints to make ice cream cone.*/
- public static final double QUARTERPINT = .25;
- /**
- * Constructor for objects of class IceCreamStation.
- * @version 2008.02.14
- */
- public IceCreamStation()
- {
- // initialise instance variables
- numCones = 0;
- numIceCream = 0;
- cashBuyCones = 0;
- cashBuyIceCream = 0;
- numSold = 0;
- numCash = 100.00;
- }
- /**
- * Constructor for input start cash.
- *
- * @param startCash starting cash
- */
- public IceCreamStation(double startCash)
- {
- // initialise instance variables
- numCones = 0;
- numIceCream = 0;
- cashBuyCones = 0;
- cashBuyIceCream = 0;
- numSold = 0;
- numCash = startCash;
- }
- /**
- * buys cones by the box.
- *
- * @param buyNumBox number of boxes
- * */
- public void buyCones(int buyNumBox)
- {
- cashBuyCones = buyNumBox * PRICEPERBOX;
- if (numCash >= cashBuyCones)
- {
- numCones = numCones + buyNumBox * CONESPERBOX;
- numCash = numCash - cashBuyCones;
- }
- else
- {
- System.out.println("Not enough cash to buy cones");
- }
- }
- /**
- * buys ice cream by the pint.
- *
- * @param numPints number of pints
- * */
- public void buyIceCream(double numPints)
- {
- cashBuyIceCream = numPints * PRICEPERPINT;
- if (numCash >= cashBuyIceCream)
- {
- numCash = numCash - cashBuyIceCream;
- numIceCream = numIceCream + numPints;
- }
- else
- {
- System.out.println("Not enough cash to buy ice cream");
- }
- }
- /**
- * sells ice cream cones.
- *
- * @param numToSell number of ice cream cones
- * @param unitPrice cost per cone
- * */
- public void sellIceCreamCones(int numToSell, double unitPrice)
- {
- if (numCones < numToSell || (numIceCream * QUARTERPINT) < numToSell)
- {
- System.out.println("not enough cones or ice cream");
- }
- else
- {
- numSold = numSold + numToSell;
- numCones = numCones - numToSell;
- numIceCream = numIceCream - (numToSell * QUARTERPINT);
- numCash = numCash + (numToSell * unitPrice);
- }
- }
- /**
- * returns number of cones in station.
- * */
- public int getConesLeft()
- {
- return numCones;
- }
- /**
- * returns how many pints of ice cream left.
- * */
- public double getIceCreamLeft()
- {
- return numIceCream;
- }
- /**
- * returns number of cones sold.
- * */
- public int getNumIceCreamConesSold()
- {
- return numSold;
- }
- /**
- * returns amount of cash in station.
- * */
- public double getCashOnHand()
- {
- return numCash;
- }
- }