using java and the code i need help with this one please In
using java and the code i need help with this one please.
In this lab, you are to write a program that calculates the sales tax, total price of all items purchased and exact change. Then, you display well-organized sales receipt on the screen. You will use Scanner class to make user input via keyboard at runtime and save these values into your program as local variables for calculation.
Create Scanner object and DecimalFormat object 1. Import Scanner class and create scanner object to read user input.
Write a program to read input from keyboard for the first item with following:
2. Input name of the first item purchased and save it to local variable “article1”. (Paint)
3. Input quantity purchased and save it to a local variable “quantity1 (1)
4. Input unit price and save it to a local variable “unit_cost1”. 8.99$
Write a program to read input from keyboard for the second item with following:
5. Input name of the second item purchased and save it to a local variable “article2”. Brush
6. Input quantity purchased and save it to a local variable “quantity2”. (2
7. Input unit price and save it to a local variable “unit_cost2”. 4.99$
8. Input amount of cash received from a client and save it to a local variable “cash”.
Calculate amounts for sales receipts . Calculate the amount of the first item by multiplying quantity and unit cost, and save it to a local variable “price1”.
10. Calculate the amount of the second item by multiplying quantity and unit cost, and save it to a local variable “price2”.
11. Calculate the sum amount of items purchased, and save it to a local variable “sub_total”.
12. Calculate the sales tax of items purchased, and save it to a local variable “tax”.
13. Calculate the total price of items including tax, and save it to a local variable “total”.
14. Calculate the change amount, and save it to local variable “change”.
15. Import DecimalFormat class and create DecimalFormat object to format floating points. Print sales receipt based on the calculation
16. Now, you need to represents the sales receipt on the screen with following format. –use escape sequences for formatting sales receipt.
public class sales_receipt
 {
 public static void main(String[] args)
 {
   //declare varables
   final double tax_rate = 0.05; //tax rate
String cashier_name = \"xxx\"; //sales person
String article1, article2; //item name for each purchased
int quantity1, quantity2; //number of quantities for each item
double unit_cost1, unit_cost2; //unit price for each item
double price1, price2; //calculates amounts of money for each item.
  double sub_total; //total price of two items without tax
   double tax; //amount of sales tax
   double total; //total price of two items including tax
   double cash; //Cash amount from user
   double change; //cash amount to the user
//create Scanner object for keyboard input
   //get first item
   //get second item
   //get amount of money tendered...
   //Calculate amounts for sales receipt
        //Create a DecimalFormat object
   //display sales receipt
   System.out.println(\"H O M E D E C O R S T O R E S\");
   System.out.println(\"R I C H M O N D O U T L E T M A L L\");
   System.out.println(\" THANK YOU - HAVE A NICE DAY \");
 System.out.println();
 }
 }
Solution
Sales_receipt.java
_________________________
import java.text.DecimalFormat;
 import java.util.Scanner;
public class Sales_receipt {
   public static void main(String[] args) {
        //declare variables
        final double tax_rate = 0.05; //tax rate
        String cashier_name = \"xxx\"; //sales person
        String article1, article2; //item name for each purchased
        int quantity1, quantity2; //number of quantities for each item
        double unit_cost1, unit_cost2; //unit price for each item
        double price1, price2; //calculates amounts of money for each item.
        double sub_total; //total price of two items without tax
        double tax; //amount of sales tax
        double total; //total price of two items including tax
        double cash; //Cash amount from user
        double change; //cash amount to the user
        //create Scanner object for keyboard input
 //Scanner object is used to get the inputs entered by the user
            Scanner sc=new Scanner(System.in);
           
        //get first item
 System.out.print(\"Enter the Name of the first item purchased :\");
 article1=sc.next();
        System.out.print(\"Enter Quantity purchased :\");
        quantity1=sc.nextInt();
        System.out.print(\"Enter Unit price :$\");
        unit_cost1=sc.nextDouble();
       
        //get second item
 System.out.print(\"Enter the Name of the second item purchased :\");
 article2=sc.next();
        System.out.print(\"Enter Quantity purchased :\");
        quantity2=sc.nextInt();
        System.out.print(\"Enter Unit price :$\");
        unit_cost2=sc.nextDouble();
       
        //get amount of money tendered...
 System.out.print(\"Enter the amount of cash receved :$\");
 cash=sc.nextDouble();
   
        //Calculate amounts for sales receipt
 price1=quantity1*unit_cost1;
 price2=quantity2*unit_cost2;
   
 sub_total=price1+price2;
   
 tax=sub_total*tax_rate;
 total=sub_total+tax;
 change=cash-total;
   
        //Create a DecimalFormat object
            //DecimalFormat class is used to format the output
            DecimalFormat df=new DecimalFormat(\"#.##\");
       //display sales receipt
        System.out.println(\"H O M E D E C O R S T O R E S\");
        System.out.println(\"R I C H M O N D O U T L E T M A L L\");
        System.out.println(\"Amount of First Item\\t$:\"+df.format(price1));
        System.out.println(\"Amount of Second Item\\t$:\"+df.format(price2));
        System.out.println(\"Sub Total\\t\\t\\t$:\"+df.format(sub_total));
        System.out.println(\"Tax\\t\\t\\t\\t$:\"+df.format(tax));
        System.out.println(\"___________________________________\");
        System.out.println(\"Total\\t\\t\\t\\t$:\"+df.format(total));
        System.out.println(\"___________________________________\");
        System.out.println(\"\ Amount of cash received $:\"+df.format(cash));
       
        System.out.println(\"Change Returned \\t$:\"+df.format(change));
       System.out.println(\" THANK YOU - HAVE A NICE DAY \");
        System.out.println();
}
}
_____________________
Output:
Enter the Name of the first item purchased :Paint
 Enter Quantity purchased :1
 Enter Unit price :$8.99
 Enter the Name of the second item purchased :Brush
 Enter Quantity purchased :2
 Enter Unit price :$4.99
 Enter the amount of cash receved :$30
 H O M E D E C O R S T O R E S
 R I C H M O N D O U T L E T M A L L
 Amount of First Item   $:8.99
 Amount of Second Item   $:9.98
 Sub Total           $:18.97
 Tax               $:0.95
 ___________________________________
 Total               $:19.92
 ___________________________________
Amount of cash received $:30
 Change Returned    $:10.08
 THANK YOU - HAVE A NICE DAY
______________Thank You




