Answer:
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
valueInDollars();
}
public static void valueInDollars() {
double currentMoney, quarters, dimes, nickels, pennies;
Scanner input = new Scanner(System.in);
System.out.print("Enter a value in dollars: ");
currentMoney = input.nextDouble();
currentMoney *= 100;
quarters = (int)currentMoney / 25;
currentMoney = currentMoney % 25;
dimes = (int)currentMoney / 10;
currentMoney = currentMoney % 10;
nickels = (int)currentMoney / 5;
currentMoney = currentMoney % 5;
pennies = currentMoney;
System.out.print("Quarters: " + quarters + "\n" + "Dimes: " + dimes + "\n" + "Nickels: " + nickels + "\n" + "Pennies: " + pennies);
}
}
Explanation:
<u>Inside the function:</u>
- Declare the variables
- Ask the user for a value in dollars
- Multiply that value by 100
- Find the amount of quarters, dimes, nickels, and pennies
- Print the values
<u>Inside the main:</u>
- Call the function