Write a program that reads an integer value between 0 and 100 (inclusive), representing the amount of a purchase in cents. Produce an error message if the input value is not in range. If the input is valid, determine the amount of change that would be received from one dollar, and print the number of quarters, dimes, nickels, and pennies that should be returned. Maximize the coins with the highest value.

Follow the format below.

Enter the purchase amount [0-100]: 36

OUTPUT:

Your change of 64 cents is given as:
2 Quarters
1 Dimes
0 Nickels
4 Pennies

HINT: 64 / 25 equals 2, and 64 % 25 equals 14

Use the following lines of code to read an integer from the user. The Scanner object will be used.

Don't forget to import the java.util.Scanner package. (import java.util.*)

public static void main(String[] args) {
// Declare a data type Scanner

int number;
Scanner scan = new Scanner(System.in);

System.out.println("Input a number: ");
number = scan.nextInt();

// …..program logic goes here …..
} // end main
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.