Question: 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
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();
} }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
