In: Computer Science
My IDE : NETBEAN JAVA
THANK YOU SO MUCH ( THE QUESTION IS ON SPECIFICATION)
Sample Run
Department Store Sales Tax and Grand Total Application
Data Entries: Enter 0 to end your input
Cost of item: 35.99
Cost of item: 27.50
Cost of item: 19.59
Cost of item: 0
All items total: $83.08
Sales tax rate (%): 6
Promotion code: 123
Discount amount: $1.00
Subtotal: $82.08
Sales tax amount: $4.92
Grand total: $87.00
Continue? y/Y/n/N: y
Data Entries: Enter 0 to end your input
Cost of item: 10.99
Cost of item: 35.50
Cost of item: 11.52
Cost of item: 21.58
Cost of item: 0
All items total: $79.59
Sales tax rate (%): 12
Tax rate should be from 6 to 10
Sales tax rate (%): 9
Promotion code: 456
Discount amount: $2.00
Subtotal: $77.59
Sales tax amount: $6.98
Grand total: $84.57
Continue? y/Y/n/N: y
Data Entries: Enter 0 to end your input
Cost of item: 95.21
Cost of item: 0
All items total: $95.21
Sales tax rate (%): 10
Promotion code: 999
Invalid promotion code. Try again
Promotion code: 789
Discount amount: $3.00
Subtotal: $92.21
Sales tax amount: $9.22
Grand total: $101.43
Continue? y/Y/n/N: Y
Data Entries: Enter 0 to end your input
Cost of item: 152.50
Cost of item: 59.80
Cost of item: 0
All items total: $212.30
Sales tax rate (%): 8
Discount amount: $21.23
Subtotal: $191.07
Sales tax amount: $15.29
Grand total: $206.36
Continue? y/Y/n/N: N
Program is terminated
Specifications
/*
* Java program that prompts the user to enter the cost of items
until
* user enters 0 to stop reading items. Then display the total items
cost
* then prompt for sales tax in a range of 6 to 10. Then prompt for
the promo code
* if the total amount is below 100 otherwise calculate a 10%
discount on the total.
* Then calculate subtotal, sales tax, and grand total and display
on java console.
* Continue the program until the user enters N or n to stop reading
user input
* and terminate the program if the user enters n or N from the
keyboard.
* */
//Store.java
import java.util.Scanner;
public class Store
{
private static Scanner kboard=new
Scanner(System.in);
public static void main(String[] args)
{
System.out.println("Department
Store Sales Tax and Grand Total Application");
double total;
String userchoice="y";
do
{
//call method to
read cost of items and get total cost of items
total=getItemsTotal();
System.out.printf("All items total: $%.2f\n",total);
System.out.printf("Sales tax rate(%%): ");
//read sales tax
value
double
salestax=Double.parseDouble(kboard.nextLine());
//validate the
sales tax in between 6 and 10
while(salestax<6 || salestax>10)
{
System.out.println("Tax rate should be from 6 to
10");
System.out.printf("Sales tax rate(%%): ");
salestax=Double.parseDouble(kboard.nextLine());
}
double
discount;
if(total<100)
{
System.out.printf("Promotion code: ");
//Read promocode
int
promocode=Integer.parseInt(kboard.nextLine());
while(!(promocode==123|| promocode==456||
promocode==789) )
{
System.out.println("Invalid
promotion code. Try again");
System.out.printf("Promotion
code: ");
//Read promocode
promocode=Integer.parseInt(kboard.nextLine());
}
//calculate discount
discount=getDiscount(promocode);
System.out.printf("Discount amount:
$%.2f\n",discount);
}
else
{
discount=total*0.10;
}
//calculate
subtotal
double
subtotal=total-discount;
System.out.printf("Subtotal: $%.2f\n",subtotal);
//calcuate sales
tax amount
double
salestaxamount=getSalesTax(subtotal, salestax);
System.out.printf("Sales tax amount:
$%.2f\n",salestaxamount);
System.out.printf("Grand total:
$%.2f\n",(subtotal+salestaxamount));
//read
userchoice
System.out.print("Continue? y/Y/n/N: ");
userchoice=kboard.nextLine();
}while(!userchoice.equals("n")
&& !userchoice.equals("N"));
System.out.println("Program is
terminated");
}//end of the method, main
/*Method to find the sales tax amount*/
public static double getSalesTax(double subtotal,
double salestax)
{
double salestaxamount=subtotal *
(salestax/ 100);
return salestaxamount;
}//end of the method, getSalesTax
/*Method to find the discount amount on
promocode*/
public static double getDiscount(int promocode)
{
int discount=0;
if(promocode==123)
discount=1;
//discount 1$
else if(promocode==456)
discount=2;
//discount 2$
else if(promocode==789)
discount=3;
//discount 3$
else
discount=0;
return discount;
}//end of the method, getDiscount
/*Method to find the total cost of items*/
public static double getItemsTotal()
{
double itemcost=0;
double totalcost=0;
System.out.println("Data Entries:
Enter 0 to end your input");
System.out.print("Cost of item:
");
itemcost=Double.parseDouble(kboard.nextLine());
while(itemcost!=0)
{
totalcost=totalcost+itemcost;
System.out.print("Cost of item: ");
itemcost=Double.parseDouble(kboard.nextLine());
}
return totalcost;
}//end of the method, getItemsTotal
}
Sample output screenshot: