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

Tuesday, May 5, 2015

Creating Your Own Java Methods and Passing Values to Them

I-Tự Tạo Một Java Method Và Passing Values Vào Method Đã Tạo.

1.1- Tự tạo method để cộng các con số tăng liên tục total +=i.
class rextester{
public static void printTotal(){  // tự tạo method nầy và phải co static
int total = 0;
for(int i = 1 ; i<=6; i++){
total +=i ;
System.out.println(total);}
}
public static void main(String[] args){
             printTotal();} // call method đã tự tạo
}
SUCCESS.
Output.
Compilation time: 1.03 sec, absolute running time: 0.14 sec,
cpu time: 0.11 sec, memory peak: 23 Mb, absolute service time: 1.19 sec
 
1
3
6
10
15
21
    
1.2- PASSING VALUES TO THE PARAMETERS OF JAVA METHOD
     * Value là integer
class rextester{
public static void passMethod(int x){ // tự tạo method nầy và phải có static
System.out.println("Passed value is :" + x ); }
public static void main(String[] args) {
      int x = 5; 
      passMethod(x); } // call và pass integer vào method đã tạo
}
SUCCESS.
Output.
Compilation time: 1.04 sec, absolute running time: 0.14 sec,
cpu time: 0.09 sec, memory peak: 22 Mb, absolute service time: 1.19 sec
Passed value is :5
 
  * Value là string
class rextester{
 public static void passMethod(String str){
System.out.println("Passed value is :" + str ); }
public static void main(String[] args) {
      String str = "Hello My Friends"; 
      passMethod(str); } // call và pass string vào method đã tạo
}
 SUCCESS.
Output.
Compilation time: 0.94 sec, absolute running time: 0.24 sec, 
cpu time: 0.12 sec, memory peak: 23 Mb, absolute service time: 1.18 sec
 Passed value is :Hello My Friends

* Value là  name
class rextester{
      public static void Person(String name){ // tự tạo method nầy.
      System.out.println("Passed Name is :" + name ); }
      public static void main(String []args){
     String name= "Henry";
              Person(name);}  // call và pass string vào method đã tạo          
}
SUCCESS.
Output.
Compilation time: 1.03 sec, absolute running time: 0.15 sec,
cpu time: 0.1 sec, memory peak: 23 Mb, absolute service time: 1.18 sec
Passed Name is :Henry

II-Tư tạo nhiều methods và pass data vào những methods đã tạo.

 2.1
      class Rextester{ 
     public static void Employee(String name){
         System.out.println("Name:"+ name );}
     public static void empAge(int x){
         System.out.println("Age:" + x );}
     public static void main(String args[]){
         String name =  "Xaoke";int x =26;
         Employee(name);empAge(x); }
     }
SUCCESS.
Output. Compilation time: 0.94 sec, absolute running time: 0.14 sec,
cpu time: 0.09 sec, memory peak: 23 Mb, absolute service time: 1.09 sec
Name:Xaoke
Age:26

2.2
    class Rextester{ 
 public static void Test(String name,int x,String skill){
System.out.println(name +" "+ x +" "+ skill);}
public static void main(String[] args){
String name= "Henry"; int x=26; String skill="Programmer";
Test(name,x,skill);}
}
SUCCESS.
output
Compilation time: 0.84 sec, absolute running time: 0.13 sec,
 cpu time: 0.06 sec, memory peak: 18 Mb, absolute service time: 0.98 sec
Henry 26 Programmer

2.3
 class Rextester{ 
 public static void Test1(String name1,int x1,String skill1){
 System.out.println(name1 +" "+ x1 +" "+ skill1);}
 public static void Test2(String name2,int x2,String skill2){
 System.out.println(name2 +" "+ x2 +" "+ skill2);}
  public static void main(String[] args){
String name1= "Henry"; int x1=26; String skill1="Programmer";
String name2= "Pano"; int x2=69; String skill2="Engineer";
Test1(name1,x1,skill1);Test2(name2,x2,skill2); }
}

SUCCESS.
output
Compilation time: 0.83 sec, absolute running time: 0.13 sec,
 cpu time: 0.06 sec, memory peak: 18 Mb, absolute service time: 0.97 sec
Henry 26 Programmer
Pano 69 Engineer



*********************************