I need this in JAVA please Youve been hired by a company to

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

Solution

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

*/

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 cu
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 cu

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site