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

Write a full java program to solve the following problem: Read in a sum of money

ID: 3549227 • Letter: W

Question

Write a full java program to solve the following problem:

Read in a sum of money and determine the number of quarters, dimes, nickels, and pennies represented in the cents portion.  You must get an optimal mix; all pennies, for example, is not allowed.

Example

With input of 43.59 you should come up with 2 quarters, 1 nickel, 4 pennies. Variable cash is a double; the rest are integers

Before you start coding, write the algorithm first.  Include this algorithm as comments in your code.  Use at least one static method (e.g., call your method Coins) to implement the solution, and call it from main.


NOTE:  all the methods written should be in the same java class and called from the main method.

Explanation / Answer

Dear,


import java.util.*;
public class MakeChange
{
          //declare a scanner object
    static Scanner console = new Scanner(System.in);

       static final int HALFDOLLAR = 50;
       static final int QUARTER = 25;
       static final int DIME = 10;
       static final int NICKEL = 5;

       public static void main (String[] args)
       {
            //declare variables
          int change;

           
          System.out.print("Enter the money: ");  
          change = console.nextInt();                       
          System.out.println();

          System.out.println("The change you entered is "
                            + change);                      

         // System.out.println("The number of half dollars "
                          // + "to be returned is "
                          // + change / HALFDOLLAR);          

          change = change % HALFDOLLAR;                     

          System.out.println("The number of quarters to be "
                           + "returned is "
                           + change / QUARTER);             

          change = change % QUARTER;                        

          System.out.println("The number of dimes to be "
                                  + "returned is "
                                  + change / DIME);         

          change = change % DIME;                           

          System.out.println("The number of nickels to be "
                           + "returned is "
                           + change / NICKEL);              

          change = change % NICKEL;                         

          System.out.println("The number of pennies to be "
                           + "returned is " + change);      
       }

}


Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote