← all problems

Cash drawer 🌶️🌶️🌶️

A cash drawer has to make change. cents holds an amount of money in cents (41 means 41 cents). Make that amount using as few coins as possible.

In the box, declare:


The five locked lines at the bottom print those five variables, one per line. For example, 41 cents is 1 quarter, 1 dime, 1 nickel and 1 penny: 4 coins, so the average coin is worth 10.25 cents.

Use / to count whole coins and % to find what is left over. Watch out for two things: what happens to the amount as you use up coins, and where the decimal part of the average comes from. Your code will be tested with several different amounts.

Main.java — the program frame below is already written; you're only completing the code in the editable box. Your code will be run several times, each with different starting values for the variables at the top.

public class Main {
    public static void main(String[] args) {
        int cents = 41;
        // ---- write your code below ----
        System.out.println(quarters);
        System.out.println(dimes);
        System.out.println(nickels);
        System.out.println(pennies);
        System.out.println(averageCoinValue);
    }
}