Name: Anonymous 2011-01-23 13:34
Tell me what's good or bad about this java class. My professor isn't going to be providing much input as this is already way better than what the assignment was expecting. I want to avoid the development of bad habits.
public class VendingMachine
{
//0=pepsi 1=drpepper 2=sprite 3=dew 4=error
private final String[] POP_TYPE = {"pepsi", "dr. pepper", "sprite", "mt det", "red blinking light"};
private final int MAX_INVENTORY = 9;
private final double COST_OF_POP = 1.50;
private int[] ariInventory = new int[4];
private double dCashDeposited;
private double dCashBox;
public VendingMachine()
{
//Fill up new pop machine
fillInventory();
//Set initial deposit value at zero
returnCash();
emptyCashBox();
}
public void insertCash(double fAdditionalDeposit)
{
//todo: Takes money and accumulates total
dCashDeposited = dCashDeposited + fAdditionalDeposit;
}
public String selectPop(int iPopSelection)
{
if (ariInventory[iPopSelection] > 0 && dCashDeposited >= COST_OF_POP){
ariInventory[iPopSelection] = ariInventory[iPopSelection] - 1;
dCashDeposited = dCashDeposited - COST_OF_POP;
dCashBox = dCashBox + COST_OF_POP;
returnCash();
return POP_TYPE[iPopSelection];}
else{
return POP_TYPE[4];} /// A red blinking light
}
public double returnCash()
{
double toBeReturned = dCashDeposited;
dCashDeposited = 0.00;
return toBeReturned;
}
public double emptyCashBox()
{
double dCashOut = dCashBox;
dCashBox = 0.0;
return dCashOut;
}
public int getInventory(int iSoda)
{
return ariInventory[iSoda];
}
public void fillInventory()
{
for (int i = 1; i <= 3; i++){
ariInventory[i] = MAX_INVENTORY;
}
}
}