Welcome to TTKS/KTQN

CLICK HERE TO OPEN

Sunday, May 10, 2015

JAVA PROGRAMS CỦA HÓA ĐƠN BÁN HÀNG.

NHỮNG HÓA ĐƠN BÁN HÀNG CÓ SALE TAX.
 1-Receipt of one item.
 public class Purchase {
 // We declare constant outside of main;all methods can access to it.
  final static double TAX_RATE = .08;
  public static void main(String[] args) {
      double itemprice = 10.25;
     // We calculate the total price here.
      double finalprice = itemprice*(1+TAX_RATE);
    System.out.println(" Your purchase  cost : "+finalprice+" with tax.");
} }
SUCCESS.
Compilation time: 0.94 sec, absolute running time: 0.24 sec,
cpu time: 0.12 sec, memory peak: 23 Mb, absolute service time: 1.19 sec
Output. Your purchase cost 11.07 with tax.
 
2-Receipt of 2 items.
 
class Rextester{  
  final static double TAX_RATE = 0.08;
  public static void main(String[] args) {
     double item1price = 10.25,item2price = 5.25,item3price = 2.25;
     double finalprice = (item1price+item2price+item3price)*(1+TAX_RATE);
 System.out.println("Your total purchase is:"+finalprice+" with tax.");
 }}
SUCCESS
Compilation time: 1.14 sec, absolute running time: 0.26 sec, 
cpu time: 0.13 sec, memory peak: 22 Mb, absolute service time: 1.41 sec
output
Your total purchase is:19.17 with tax.

3- Receipt for T-Shirts Shop.

    USING JAVA SCANNER
class ideone{
public static void main (String[] args) {
      System.out.println (" T-SHIRTS SHOP ESTABLISHED IN 1986 ");
      System.out.println (" Owner : Henry Baxao Xaoke ");
      System.out.println ("----------------------------------");
     int tsmall, tmed, tlarge, xlarge ;
     double price1 =1.5, price2 = 2.5, price3 = 3.25, price4= 3.75, total1, total2 ;
     Scanner scan = new Scanner (System.in);
     System.out.println (" *Muôn bao nhiêu Small,Medium,Large,Xlarge ? : ");
          tsmall = scan.nextInt(); tmed = scan.nextInt();
          tlarge = scan.nextInt(); xlarge = scan.nextInt();
System.out.println (" *Ban mua : " +tsmall+ " "+ "SM" +";"+tmed+" "+ "MD" +";"+tlarge+" " +"LG" +";"+ xlarge+ " " +"XLG");  
total1 =(tsmall*price1 + tmed*price2 + tlarge*price3 + xlarge*price4);
total2 =(tsmall*price1+ tmed*price2+ tlarge*price3+ xlarge*price4)*1.08;
System.out.printf (" *Giá tông công không có Tax :  %.2f%n ", total1);
System.out.printf (" *Giá tông công có Tax :  %.2f%n ", total2);
 System.out.println (" THANK YOU-CÁM ON" );
// Viết double total, nhưng nếu dùng format thì phải đổi ra %.2f%n mới chọn được // // những con số sau dấu chấm theo ý muốn.
}}
SUCCESS.
Outpt.
T-SHIRTS SHOP ESTABLISHED IN 1986 
 Owner : Henry Baxao Xaoke 
----------------------------------
 *Muôn bao nhiêu Small,Medium,Large,Xlarge ? : 
 *Ban mua : 8 SM;6 MD;4 LG;2 XLG
 *Giá tông công không có Tax :  47.50
  *Giá tông công có Tax :  51.30
  THANK YOU-CÁM ON
 
4-Receipt Written With Java Formatting.
       Using Java Formatter.
        class Rextester{      
       private double total = 0;
       private double total2 = 0;
       private Formatter f = new Formatter(System.out);
      
       public void printTitle(){
        f.format("%-15s %10s %15s \n", "ITEM", "QTY","PRICE");
        f.format("%-15s %10s %15s \n", "----","----" ,"----");}

       public void print(String name, int qty, double price){  
        f.format("%-15s %10d %15.2f \n", name, qty, price);total+=qty;
        total2+=price; }
      
       public void printTotal(){
       f.format("%-15s %10s %15.2f\n", "TAX", "   " , total2*0.08);
       f.format("%-15s %10s %15s\n",    "   ",  "----", "----");
       f.format("%-15s %10.1s %15.2f\n", "TOTAL", total, total2*1.08);}
       
       public static void main(String[] args){
       receipt.printTitle();
       receipt.print("T-shirts small ", 4, 12.00);
       receipt.print("Ceramic spoons", 2, 2.50);
       receipt.print("Plastic bucket",1, 4.25);
       receipt.print("Aluminium foil",2, 2.50);
       receipt.print("Saran", 2, 5.00);
       receipt.printTotal();
}}
SUCCESS . Compilation time: 0.73 sec, absolute running time: 0.14 sec,
cpu time: 0.06 sec, memory peak: 18 Mb,absolute service time: 0.88 sec
Output.
ITEM                   QTY           PRICE 
----                  ----            ---- 
T-shirts small           4           12.00 
Ceramic spoons           2            2.50 
Plastic bucket           1            4.25 
Aluminium foil           2            2.50 
Saran                    2            5.00 
TAX                                   2.10
                      ----            ----

TOTAL                   11           28.35

No comments:

Post a Comment