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

1. Member
Join Date
Jun 2012
Posts
1
Rep Power
0

## 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;

}
}

2. Moderator
Join Date
Jul 2010
Location
California
Posts
1,641
Rep Power
10

3. Member
Join Date
Jun 2012
Location
Posts
25
Rep Power
0

## 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...
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!
"None but ourselves can free our minds."
- Bob Marley.
Last edited by Tha Boss; 06-16-2012 at 06:37 AM.

4. Moderator
Join Date
Jul 2010
Location
California
Posts
1,641
Rep Power
10

## 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.

5. Member
Join Date
Jun 2012
Location
Posts
25
Rep Power
0

## 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"?

"(In life)... every second counts because there's no second try."

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

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.

7. Member
Join Date
Jun 2012
Location
Posts
25
Rep Power
0

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

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..
"He who controls others may be powerful but he who has mastered himself is mightier still."
- Lao Tzu.
Last edited by Tha Boss; 06-16-2012 at 05:47 AM.

8. Moderator
Join Date
Jul 2010
Location
California
Posts
1,641
Rep Power
10

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

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 ).

9. Member
Join Date
Jun 2012
Location
Posts
25
Rep Power
0

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

"Spoon-feeding is giving somebody a full solution before that person has really put a full effort into solving the problem."
I think the poor lad put some amount of effort, but with reasonable doubt it was a bit far-fetched. That being said, I accept that it was on the bit on the "spoon-feeding" side but you could have took out some parts, you took out literally everything, so you're actually taking steps backwards, the forum is here to help. What about giving me an example of a good post instead of totally thwarting attempts to help, and.. I can't stress this enough .. NOT MAKING ANY CONTRIBUTION TO SOLVING THE PROBLEM!
"It never ceases to surprise me at the infinite capacity of the human mind to resist the introduction of useful knowledge."
- Thomas Raynesford Lounsbury.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•