Good Morning World! As I start yet another semester learning to make new, better codes, I'd like to post an update to one of my codes I previously posted for calculating the estimate cost of items purchased after applying Sales Taxes in the Province of Quebec, Canada.
Previously, the effective sales tax in Quebec was 7.875% (QST) and the sales tax across Canada is 5% (GST), making a total tax rate of 12.875% for Sales Taxes combined in Quebec (QST+GST) for the year 2010.
Currently, the effective sales tax in Quebec is 8.925% (QST) and the sales tax across Canada is 5% (GST), making a total tax rate of 13.925% for Sales Taxes combined in Quebec (QST+GST) for the year 2011.
The following code can be used as a dummy program imitating a cash register at any general store (Grocery, Fast Food, Restaurant, etc.).
Stay tuned...
~DanceLink
-------------------------------------------------------------------------------------------------------------
import java.util.Scanner;
import java.text.NumberFormat;
public class QC_Price {
/**
* This program is intended to approximate the total cost of items purchased after taxes.
* @author A. Wright
* @version 1.1, January 2011
*/
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
double PST=0.08925, GST=0.05;
double subtotal=0,total;
int op1, items;
double[] prices;
NumberFormat currencyFormatter;
System.out.println("Would you like to:"
+"\n1.Calculate sub-total AND total costs?"
+"\n2.Calculate ONLY total cost?");
op1=kb.nextInt();
while(op1<1||op1>2){
System.out.println("That is not a valid option.\nPlease enter a valid option:");
System.out.println("Would you like to:"
+"\n1.Calculate sub-total AND total costs?"
+"\n2.Calculate ONLY total cost?");
op1=kb.nextInt();
}
if(op1==1){
System.out.println("Please enter number of items to be inputed:");
items=kb.nextInt();
while(items<0){
System.out.println("That is not a valid number.\nPlease enter a positive value:");
System.out.println("Please enter number of items to be inputed:");
items=kb.nextInt();
}
if(items==0){
System.out.println("No item quantity was specified.\nSystem aborting operation.");
System.exit(0);
}
prices=new double[items];
System.out.println("Please enter item prices as advertized:");
for(int i=0;i<items;i++){
System.out.print((i+1)+". ");
prices[i]=kb.nextDouble();
subtotal += prices[i];
}
String currencySubtotal,currencyGST,currencyPST,currencyTotal;
currencyFormatter=NumberFormat.getCurrencyInstance();
currencySubtotal=currencyFormatter.format(subtotal);
currencyGST=currencyFormatter.format(((subtotal*GST)));
currencyPST=currencyFormatter.format(((subtotal*PST)));
System.out.println("The subtotal amount is: "+currencySubtotal+" CDN.");
total=subtotal+(subtotal*(GST+PST));
currencyTotal=currencyFormatter.format(total);
System.out.println("The total GST amount is: "+currencyGST+" CDN.");
System.out.println("The total PST amount is: "+currencyPST+" CDN.");
System.out.println("The total amount is: "+currencyTotal+" CDN.");
System.exit(0);
}
if(op1==2){
System.out.println("Please enter sub-total costs:");
subtotal=kb.nextDouble();
while(subtotal<0){
System.out.println("That is not a valid price.\nPlease enter a positive value:");
System.out.println("Please enter sub-total costs:");
subtotal=kb.nextDouble();
}
total=subtotal+(subtotal*(GST+PST));
String currencysubtotal,currencygst,currencypst,currencytotal;
currencyFormatter=NumberFormat.getCurrencyInstance();
currencysubtotal=currencyFormatter.format(subtotal);
currencygst=currencyFormatter.format(((subtotal*GST)));
currencypst=currencyFormatter.format(((subtotal*PST)));
currencytotal=currencyFormatter.format(total);
System.out.println("The subtotal amount is: "+currencysubtotal+" CDN.");
System.out.println("The total GST amount is: "+currencygst+" CDN.");
System.out.println("The total PST amount is: "+currencypst+" CDN.");
System.out.println("The total amount is: "+currencytotal+" CDN.");
System.exit(0);
}
}
}
-----------------------------------------------------------------------------------------------------------
Good Luck with the new Semester!!! <3
ReplyDelete