A cashier distributes change using the maximum number of five dollar bills, followed by one dollar bills. For example, 19 yields 3 fives and 4 ones. Write a single statement that assigns the number of one dollar bills to variable numOnes, given amountToChange. Hint: Use the % operator.

Report
Question

Please briefly explain why you feel this question should be reported .

Report
Cancel

2.7.2 Compute Change

A cashier distributes change using the maximum number of five dollar bills, followed by one dollar bills. For example, 19 yields 3 fives and 4 ones. Write a single statement that assigns the number of one dollar bills to variable numOnes, given amountToChange. Hint: Use the % operator.

import java.util.Scanner;

public class ComputingChange {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
int amountToChange;
int numFives;
int numOnes;

amountToChange = scnr.nextInt();
numFives = amountToChange / 5;

/* Your solution goes here */

System.out.print(“numFives: “);
System.out.println(numFives);
System.out.print(“numOnes: “);
System.out.println(numOnes);
}
}

in progress 0
admin 3 months 2023-02-28T11:08:12+00:00 1 Answer 5 views Teacher 0

Answer ( 1 )

    0
    2023-02-28T11:08:28+00:00

    Please briefly explain why you feel this answer should be reported .

    Report
    Cancel

    The single statement that assigns the number of one dollar bills to the variable numOnes is:

    makefile
    numOnes = amountToChange % 5;

    This statement uses the % operator to compute the remainder when amountToChange is divided by 5, which gives the number of dollars that cannot be represented using a five dollar bill. These dollars are given in one dollar bills, so we assign this value to the variable numOnes.

Leave an answer

Browse

By answering, you agree to the Terms of Service and Privacy Policy.