Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

CHALLENGE ACTIVITY 2.9.2: Compute change. A cashier distributes change using the

ID: 3876396 • Letter: C

Question

CHALLENGE ACTIVITY 2.9.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; 1 test p550 - N m at un o co OY public class ComputingChange { public static void main(String[] args) { int amountToChange; int numFives; int numOnes; DIIDII All tests passed 18 amountToChange - 19; numFives = amountToChange / 5; 11 12 numOnes - (amountToChange) / ; 13 14 15 16 17 System.out.print("numFives: "); System.out.println(numFives); System.out.print("numOnes: "); System.out.println( numOnes); Run

Explanation / Answer

public class ComputingChange {

  

  

   public static void main(String[] args) {

       int amoutToChange;

       int numFives;

       int numOnes;

      

       amoutToChange = 19;

      

       numFives = amoutToChange/5;

           //assign a one dollar bills to numOnes for given amount to change

       numOnes = amoutToChange%5;

      

       System.out.println("numFives: ");

       System.out.println(numFives);

       System.out.println("numOnes: ");

       System.out.println(numOnes);

      

   }

}

Sample OutPut:

numFives:

3

numOnes:

4