Java Task #1 – Change Maker The task was: Write the pseudocode for helping a cas
ID: 3930669 • Letter: J
Question
Java
Task #1 – Change Maker
The task was: Write the pseudocode for helping a cashier give you the correct change. Assume that a person brings hundreds to pennies to you and wishes to the receive quarters, dimes, and nickels back. There is a single input of the number of pennies given to the cashier. There will be several outputs: the number of quarters, dimes, nickels, and remaining pennies to be returned.
For this program, you will ask the user to enter the number of pennies that he/she has. The output will be the Number of Quarters, Number of Dimes, Number of Nickels, and Number of Pennies.
I recommend that you use the MOD function for this problem. I’ll assume that you’ll use the pseudocode example that I showed in class. Provide me with just the source code for this task.
Explanation / Answer
ChangeTest.java
import java.util.Scanner;
public class ChangeTest {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("Enter the number of pennies: ");
int cents = scan.nextInt();
int quarters = cents / 25;
cents = cents % 25;
int dimes = cents/ 10;
cents = cents % 10;
int nickels = cents / 5;
cents = cents % 5;
int penny = cents;
System.out.println("Number of quarters: "+quarters);
System.out.println("Number of dimes: "+dimes);
System.out.println("Number of nickels: "+nickels);
System.out.println("Number of pennies: "+penny);
}
}
Output:
Enter the number of pennies: 119
Number of quarters: 4
Number of dimes: 1
Number of nickels: 1
Number of pennies: 4
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.