# NEED HELP! converting change given to money denominatons

• June 15th, 2012, 05:20 PM
Mrod359
NEED HELP! converting change given to money denominatons
Hi Guys!

Well, my problem is i seem to not be able to convert the amountGiven back into change, such as dollars, quarters nickels, dimes, pennies. Heres my code: i hope its not to sloppy.. Ive just about ran out of ideas..

import java.text.NumberFormat;

public class Cashier {

private static final double QUARTER_VALUE = 0.25;
private static final double DIME_VALUE = 0.1;
private static final double NICKEL_VALUE = 0.05;
private static final double PENNY_VALUE = 0.01;
private static final double DOLLAR_VALUE = 1.00;

private static String name;
private static double total;
private double cost;
private int numOfItems;
private double aver;
private double aver1;
private double aver2;
private double change;
private double amountGiven;
String s;

private double penny,nickel,dime,quarter,dollar;

NumberFormat nf = NumberFormat.getCurrencyInstance();

public Cashier()
{
name = "";
s = "";
total = 0.0;
cost = 0.0;
numOfItems = 0;
}

public void add(String name, double cost)
{
this.name = name;
this.cost = cost;
s = s + name + "....." + cost + "\n";
numOfItems = numOfItems + 1;
total = total + cost;
}

public void average()
{
aver = total / numOfItems;
}

public void tendered(double Amount)
{
amountGiven = Amount;
}

public double getAG()
{
return amountGiven;
}

public void makeChange()
{
change = amountGiven - total;
}

public String getName()
{
return s;
}

public double getCost()
{
return cost;
}

public int getNumOfItems()
{
return numOfItems;
}

public double getTotal()
{
}

public double getAver()
{
return aver;
}

public double getChange()
{
return change;
}

public double Quarter()
{
quarter =(int) change / 25;
change = change % 25;

return quarter;

}

public double Dime(){

dime = (change / 25)/10;

return dime;

}
public double Dollar(){

dollar = (int)amountGiven / 100;
amountGiven = amountGiven * 100;

return dollar;

}

public double nickel(){

nickel = (change / 10)/5;

return nickel;

}
public double Penny(){

penny = (change / 5)/1;

return penny;

}
}
• June 15th, 2012, 05:30 PM
copeg
Re: NEED HELP! converting change given to money denominatons
This thread has been cross posted here: