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

I need this in JAVA please!! You\'ve been hired by a company to write a Java con

ID: 3926563 • Letter: I

Question

I need this in JAVA please!!

You've been hired by a company to write a Java console application that determines the amount and type of change to return to a customer for a given sale. Use a validation loop to prompt and get from the user the sale amount in the range $1-8. Then use a validation loop to prompt and get from the user the amount tendered by the customer to insure it is at least the sale amount. Calculate the number of fives, ones, quarters, dimes, nickels, and pennies that should be returned to the customer.

Format the following output in two columns with the first column containing a label and the second column containing the result:

          The two inputs.

          The change amount.

          The number of:

~ Fives

~ Ones

                   ~ Quarters

                   ~ Dimes

                   ~ Nickels

                   ~ Pennies

Format any dollar values to two decimal places. Continue to prompt the user for sales until they enter sale amount -22. Use this data for the last three inputs:

     Sale amount($)       Amount tendered($)

                      1.75                                    2

                      2.47                               5.50

                      7.11                                  10

Explanation / Answer

import java.util.Scanner;
class Main {
public static void main(String[] args) {
   Scanner sc = new Scanner(System.in);
   double sales,tender;
   while(true){
       System.out.println("---------------Calculate Change-----------------");
       // loop for input validation of sales
       while(true){
           System.out.print("Sales:");
           sales = sc.nextDouble();
           if(sales>=1 && sales<9)
               break;
           else if(sales == -22){
               return;                   // exit the program if sales is -22
           }
           else{
               System.out.println("Invalid Sales.");
           }
       }
       // loop for input validation of tender.
       while(true){
           System.out.print("Tender:");
           tender = sc.nextDouble();
           if(tender<sales){
               System.out.println("Tender should be greater than sales.");
           }
           else{
               break;
           }
       }
       double changeDue = tender - sales;
       System.out.println("Change Amount:"+changeDue);
       int change = (int)(Math.ceil(changeDue*100));
   int dollars = Math.round((int)change/100);
   change=change%100;
   int quarters = Math.round((int)change/25);
   change=change%25;
   int dimes = Math.round((int)change/10);
   change=change%10;
   int nickels = Math.round((int)change/5);
   change=change%5;
   int pennies = Math.round((int)change/1);
  
   System.out.println("~Dollars: " + dollars);
   System.out.println("~Quarters: " + quarters);
   System.out.println("~Dimes: " + dimes);
   System.out.println("~Nickels: " + nickels);
   System.out.println("~Pennies: " + pennies);
   }
}
}

/*

sample output

*/

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