# Need help with a homework problem

• June 18th, 2013, 04:46 AM
x 0i
Need help with a homework problem
Having trouble with this one...

Write a Java program that will distribute the total amount of money found in a piggy bank into the following currencies: half dollars, quarters, dimes, nickels and pennies. The distribution will begin with the largest currency and move downward to the smallest. The process will follow these steps:

1.) The program is to prompt the user for the currency found in the bank;
2a.) find the largest equivalent number of half dollars present in the total amount;
2b.) reduce the total amount of money by the value of the half dollar amount; proceed by repeated the above process (steps 2a and 2b, using the new remaining dollar amount) to find the largest equivalent number of quarters, then dimes, then nickels, and finally, the remaining pennies
3.) the program will then display the equivalent number of half dollars, quarters, then dimes, then nickels, and finally, the remaining pennies.

Sample program:
Please enter the total dollar amount in the piggy bank: \$16.72
In \$16.72 there are:
33 half dollar(s), 0 quarter(s), 2 dime(s), 0 nickel(s), and 2 cent(s).

The output must be exactly the same as that
• June 18th, 2013, 02:52 PM
Mercifies
Re: Need help with a homework problem
Can you post some code to see what you have so far?
• June 18th, 2013, 04:21 PM
x 0i
Re: Need help with a homework problem
Code:

import java.util.Scanner;
import java.text.DecimalFormat;
public class ProgramIII
{
public static void main(String [] args)

{
DecimalFormat f = new DecimalFormat("\$0.00");
double total = 0;
double hf = 0;
double q = 0;
double d = 0;
double n = 0;
double c = 0;

Scanner kbd =  new Scanner(System.in);

System.out.println("Enter amount of money found in piggy bank: ");
total = kbd.nextInt();
System.out.println();

hf = total / .50;
q =
d =
n =
c =

System.out.println("In " + (f.format(total)) + " there are: ");
System.out.println("                " +