Question

2. Write a JAVA program that prints the numbe r of quarters, dimes, nickels, and pennies...

2. Write a JAVA program that prints the numbe r of quarters, dimes, nickels, and pennies that a customer should get back as change. Declare and initialize all memory locations as integers. On Output show the original change amount as a monetary amount with the two positions of decimal. Run your
program once by performing a compile-time initializations using 92 cents for the calue to be converted.

Go into your source code and change the 92 to 27. Return the application. Be sure to desk check your solution.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
public class Denominations {
  public static void main(String args[]){
    float amount = 92;
    if(amount > 25){
      System.out.print((int)(amount/25));
      amount = (float) (amount - ((int)(amount/25) * 25));
    }
    else {
      System.out.print(0);
    }
    System.out.print(" quarters ");
    if(amount > 10){
      System.out.print((int)(amount/10));
      amount = (float) (amount % 10);
    }
    else {
      System.out.print(0);
    }
    System.out.print(" dimes ");
    if(amount > 0.05){
      System.out.print((int)(amount/5));
      amount = (float)(amount % 5);
    }
    else {
      System.out.print(0);
    }
    System.out.print(" nickels ");
    if(amount > 0.01){
      System.out.print(((int)(amount/1)));
      amount = (float) (amount % 1);
    }
    else {
      System.out.print(0);
    }
    System.out.println(" pennies.");
  }
}

3 quarters 1 dimes 1 nickels 2 pennies Process finished with exit code 0

==============================================================

public class Denominations1 {
  public static void main(String args[]){
    float amount = 27;
    if(amount > 25){
      System.out.print((int)(amount/25));
      amount = (float) (amount - ((int)(amount/25) * 25));
    }
    else {
      System.out.print(0);
    }
    System.out.print(" quarters ");
    if(amount > 10){
      System.out.print((int)(amount/10));
      amount = (float) (amount % 10);
    }
    else {
      System.out.print(0);
    }
    System.out.print(" dimes ");
    if(amount > 0.05){
      System.out.print((int)(amount/5));
      amount = (float)(amount % 5);
    }
    else {
      System.out.print(0);
    }
    System.out.print(" nickels ");
    if(amount > 0.01){
      System.out.print(((int)(amount/1)));
      amount = (float) (amount % 1);
    }
    else {
      System.out.print(0);
    }
    System.out.println(" pennies.");
  }
}

Add a comment
Know the answer?
Add Answer to:
2. Write a JAVA program that prints the numbe r of quarters, dimes, nickels, and pennies...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Your program must meet the following specifications: 1. At program start, assume a stock of 10 nickels, 10 dimes, 10...

    Your program must meet the following specifications: 1. At program start, assume a stock of 10 nickels, 10 dimes, 10 quarters, and 10 pennies. 2. Repeatedly prompt the user for a price in the form xX.xx, where X denotes a digit, or to enter q' to quit 3. When a price is entered a. If the price entered is negative, print an error message and start over requesting either a new price or to quit (indicated by entering a 'q)...

  • Write a program called "ConvertPennies" to input an integer value representing a number of pennies and...

    Write a program called "ConvertPennies" to input an integer value representing a number of pennies and convert it to its equivalent number of Dollars, Quarters, Dimes, Nickels and Pennies. Following is the result of the execution of this program for 292 pennies. Enter the amount of pennies to convert: 292 pennies is equal to 2 one dollar bills 3 quarters 1 dimes 1 nickels 2 pennies Have a nice day! This is given: //********************************************************************** // Programmer: Your first and last...

  • Write a C program that calculates exact change. In order to receive full credit, please remember...

    Write a C program that calculates exact change. In order to receive full credit, please remember that only int arithmetic is exact, so you’ll need to break up your double into two ints, the one before the decimal point and the one after the decimal point. Another point worth mentioning is that the % operator gives the remainder. In other words, when working with int values, 9 / 5 = 1 whereas 9 % 5 = 4. Keep this in...

  • All items at a "Penny Fair" are priced less than $1.00. Write a program that makes...

    All items at a "Penny Fair" are priced less than $1.00. Write a program that makes change with a minimum number of coins when a customer pays for an item with a one dollar bill. Prompt for the item price in cents, report the change due, and the number of coins of each denomination required. Use only quarters, dimes, nickels, and pennies for change (no 50 cent pieces). See sample output but your program should work for any item price....

  • write a PHP program makes change for a given number of cents. The program should ask...

    write a PHP program makes change for a given number of cents. The program should ask the user for the amount of cents and then output the change for specific denominations of ten dollar bills, five dollar bills, one dollar bills, quarters, dimes, nickels, and pennies. Here is a sample program output for an input of 265 cents: Change for 2 dollars and 65 cents : 0 ten dollar bills 0 five dollar bills 2 one dollar bills 2 quarters...

  • Write a program called CountCoins.java that prompts the user for the input file name (you can...

    Write a program called CountCoins.java that prompts the user for the input file name (you can copy the getInputScanner() method given in the ProcessFile assignment) then reads the file. The file contains a series of pairs of tokens, where each pair begins with an integer and is followed by the type of coin, which will be “pennies” (1 cent each), “nickels” (5 cents each), “dimes” (10 cents each), or “quarters” (25 cents each), case-insensitively. Add up the cash values of...

  • How do I type 2.18 into java? We have to make up a scenario and put...

    How do I type 2.18 into java? We have to make up a scenario and put it into netbeans java. range increases byte, short, int, long, float, double Lab2: Calculate Changes Problem Statement: This program lets the user enter the amount in decimal representing dollars and cents and output a report listing the monetary equivalent in single dollars, quarters, dimes, nickels, and pennies. Your program should report maximum number of dollars, then the maximum number of quarters, and so on,...

  • Vending Machine (Python 3) Thinking Outside the box Write a program that asks the user to...

    Vending Machine (Python 3) Thinking Outside the box Write a program that asks the user to enter a bill value (1 = $1 bill, 5 = $5 bill, etc.) and the price of an item they want to buy in pennies and calculate their change amount in dollars, quarters, dimes, nickels, and pennies. Your code should start like this: ## # This program simulates a vending machine that gives change # Define constants PENNIES PER DOLLAR = 100 PENNIES PER...

  • Can you please help me with creating this Java Code using the following pseudocode? Make Change C...

    Can you please help me with creating this Java Code using the following pseudocode? Make Change Calculator (100 points + 5 ex.cr.)                                                                                                                                  2019 In this program (closely related to the change calculator done as the prior assignment) you will make “change for a dollar” using the most efficient set of coins possible. In Part A you will give the fewest quarters, dimes, nickels, and pennies possible (i.e., without regard to any ‘limits’ on coin counts), but in Part B you...

  • Objectives: Use the while loop in a program Use the do-while loop in a second program...

    Objectives: Use the while loop in a program Use the do-while loop in a second program Use the for loop in a third program Instructions: Part A. Code a for loop to print the Celsius temperatures for Fahrenheit temperatures 25 to 125. C = 5/9(F – 32).Output should be in a table format: Fahrenheit Celsius 25 ? . . . . . . . . Turn in the source and the output from Part A. Part B. Code a while...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT