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

In java script, write a change calculator that will run on BlueJ. You will first

ID: 3757596 • Letter: I

Question

In java script, write a change calculator that will run on BlueJ. You will first get five bills and the corresponding amount paid for that bill (both doubles) from the user, and then for each one you will print the optimal change in dollars, quarters, dimes, nickels, and pennies.

Criteria:

Get five bill and amount paid values from user and store in two arrays.

Use loop to process each change value in array.

Calculate and print optimal change for each value.

Don't print a coin type if not needed for optimal change.

Print singular/plural correctly for a given coin type.

Print "no change" for a user input of 0.

Explanation / Answer

import java.util.*;

import java.text.*;

public class proj4  

{  

    public static void main(String args[ ] )  

      {  

         Scanner s = new Scanner(System.in);

         System.out.println("Dollar Change Program ");

         int purchase;

         int changevalue;

         int quarters;

         int dimes;

         int nickels;

         int pennies;

         System.out.print(" Enter 5 change values (< $1.00):");

         changevalue = Integer.parseInt(s.nextLine());

         System.out.println(" Change Value (< $1.00): " + quarters + " ");

         changevalue = 99 - purchase;

         System.out.println("Change value : " + changevalue + "cents ");

         quarters = changevalue / 25;  

         changevalue= changevalue % 25;  

         dimes    = changevalue / 10;

         changevalue = changevalue % 10;  

         nickels = changevalue / 5;

         pennies = changevalue % 5;  

         System.out.println("No change    " + 0 );

         System.out.println("quarters     " + quarters );

         System.out.println("dimes         " + dimes );

         System.out.println("nickels       " + nickels );

         System.out.println("pennies      " + pennies + " " );

     }  

  }


you can also try this code

package givingChange;

import javax.swing.JOptionPane;

public class GivingChange {

    public static void main(String [] args) {

        String amount;

        int price, paid, change;

        int dollars, quarters, dimes, pennies, nickels;

        amount = JOptionPane.showInputDialog("Enter amount due");

        price = Integer.parseInt(amount);

        amount = JOptionPane.showInputDialog("Enter amount paid");

        paid = Integer.parseInt(amount);

        change = paid - price;

        dollars = change / 100;

        int left = change % 100;

        quarters = left / 25;

        left = left % 25;

        dimes = left / 10;

        left = left % 10;

        nickels = left / 5;

        left = left % 5;

        pennies = left / 1;

        if (dollars > 0) {

            System.out.println(dollars + " dollars");

        } // End of "if (dollars...)"

        if (quarters > 0) {

            System.out.println(quarters + " quarters");

        } // End of "if (quarters...)"

        if (dimes > 0) {

            System.out.println(dimes + " dimes");

            if (nickels > 0) {

                System.out.println(nickels + " nickels");

            }

            if (pennies > 0) {

                System.out.println(pennies + " pennies");

            }

        } // End of "if (dimes...)"

    } // End of main()

} // End of class definition

import java.util.*;

import java.text.*;

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