79.6k views
0 votes
3. Write a project named Money that prompts for and reads a double value representing a monetary amount. Then determine the fewest number of each bill and coin needed to represent that amount, starting with the highest (assume that a ten-dollar bill is the maximum size need). For example, if the value entered is 47.63 (forty-seven dollars and sixty-three cents), then the program should print the equivalent amount as:

1 Answer

3 votes

Answer: Provided in the explanation segment

Step-by-step explanation:

The following code provides answers to the given problem.

import java.util.*;

public class untitled{

public static void main(String[] args)

{int tens,fives,ones,quarters,dimes,nickles,pennies,amt;

double amount;

Scanner in = new Scanner(System.in);

System.out.println("What do you need to find the change for?");

amount=in.nextDouble();

System.out.println("Your change is");

amt=(int)(amount*100);

tens=amt/1000;

amt%=1000;

fives=amt/500;

amt%=500;

ones=amt/100;

amt%=100;

quarters=amt/25;

amt%=25;

dimes=amt/10;

amt%=10;

nickles=amt/5;

pennies=amt%5;

System.out.println(tens +" ten dollar bills");

System.out.println(fives +" five dollar bills");

System.out.println(ones +" one dollar bills");

System.out.println(quarters +" quarters");

System.out.println(dimes +" dimes");

System.out.println(nickles +" nickles");

System.out.println(pennies +" pennies");

}

}

cheers i hope this helped !!

User TurtleToes
by
5.4k points