# NEED HELP! converting change given to dollars, quarters, dimes, etc..

• 06-16-2012, 12:28 AM
mrodr359
NEED HELP! converting change given to dollars, quarters, dimes, etc..
Hi guys!

Well Im completely lost in my assignment for school, i have no idea how to convert the change given back to the user, into dollars, quarters, dimes, nickels, pennies..

Heres my code: hope its not to messy

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;

}
}
• 06-16-2012, 12:30 AM
doWhile
Re: NEED HELP! converting change given to dollars, quarters, dimes, etc..
• 06-16-2012, 03:06 AM
Tha Boss
Re: NEED HELP! converting change given to dollars, quarters, dimes, etc..
Ok... so, the first problem, I tried to run your code and got method errors. Secondly, there's no input being taken from the user, what are you supposed to make change for? your program can't just pull numbers out of the sky.... unless you tell it to.Thirdly why are you using methods? and so many to boot... did your instructions say you have to? I think the problem can be solved with much much shorter code. I also found it hard to follow what you're attempting to do in your code as you declared alot of unnecessary variables and did unnecessary calculations - averages??? - number of items???.
But that being said.. lets get to fixing this... please don't take the above the wrong way... :(devil):
I see some attempt in your program to format the currency, your program will not be outputting currency, if I'm not mistaken, purely numbers, and should be treated as such even though you're dealing with money.
- CHEERS!
Quote:

"None but ourselves can free our minds."
- Bob Marley.
• 06-16-2012, 03:56 AM
doWhile
Re: NEED HELP! converting change given to dollars, quarters, dimes, etc..
@Tha Boss, please don't make it a habbit of doing someone else's homework for them. Amongst its many problems is that it robs them the opportunity to problem solve, and its academic dishonesty. Definitely something forums such as this are not here to perpetuate, and as a result your post has been edited.
• 06-16-2012, 04:04 AM
Tha Boss
Re: NEED HELP! converting change given to dollars, quarters, dimes, etc..
wait a minute.. that took time to do... u just robbed me of time :(( ... I think I commented in it enough so the readers will be informed on how it's solved.. wouldn't that count as a "lesson" and not a "spoon-feed"?

Quote:

"(In life)... every second counts because there's no second try."
• 06-16-2012, 04:37 AM
Fubarable
Re: NEED HELP! converting change given to dollars, quarters, dimes, etc..
Quote:

Originally Posted by Tha Boss
wait a minute.. that took time to do... u just robbed me of time :(( ... I think I commented in it enough so the readers will be informed on how it's solved.. wouldn't that count as a "lesson" and not a "spoon-feed"?

Wouldn't the original poster obtain much more benefit if you gave suggestions and nudges so that they would be able to discover the solution on their own? Sure, spoon feeding the OP the solution is a lot easier for us to do as it usually involves less give and take, but many here, myself included, feel that by doing this we cheat the original poster out of a valuable learning experience.
• 06-16-2012, 04:45 AM
Tha Boss
Re: NEED HELP! converting change given to dollars, quarters, dimes, etc..
Quote:

Originally Posted by Fubarable
Wouldn't the original poster obtain much more benefit if you gave suggestions and nudges so that they would be able to discover the solution on their own? Sure, spoon feeding the OP the solution is a lot easier for us to do as it usually involves less give and take, but many here, myself included, feel that by doing this we cheat the original poster out of a valuable learning experience.

Ok, understood.. but still not fair enough.. because he removed the entire solution, why not just remove some parts in respects to my attempts to help? he only pointed out that the thread existed on another forum. He put no solution on the table, but yet he removed mine and left NOTHING...
abused power..
Quote:

"He who controls others may be powerful but he who has mastered himself is mightier still."
- Lao Tzu.
• 06-16-2012, 05:06 AM
doWhile
Re: NEED HELP! converting change given to dollars, quarters, dimes, etc..
Quote:

Originally Posted by Tha Boss
Ok, understood.. but still not fair enough.. because he removed the entire solution, why not just remove some parts in respects to my attempts to help? he only pointed out that the thread existed on another forum. He put no solution on the table, but yet he removed mine and left NOTHING...
abused power..

I stand by my decision, and Fubarable couldn't have done better stating my reasons (I do point you to the following article as well: The Problem with Spoon-feeding ).
• 06-16-2012, 05:18 AM
Tha Boss
Re: NEED HELP! converting change given to dollars, quarters, dimes, etc..