keymasterviriya1150

Untitled

Nov 26th, 2015
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 13.36 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.ArrayList;
  3. import static java.lang.System.out;
  4. class Test
  5. {
  6.         static Scanner sc=new Scanner(System.in);
  7.         public static void main(String[]dog)
  8.         {
  9.            ArrayList<salary> a = new ArrayList<salary>();
  10.            a.add(new salary(111,"Smith",10000));
  11.            a.add(new salary(222,"Anna",20000));
  12.            
  13.            ArrayList<Hourly> b= new ArrayList<Hourly>();
  14.            b.add(new Hourly(333,"Paul",200));
  15.            b.add(new Hourly(444,"Pete",300));
  16.            //formation1
  17.            for(int i=0;i<2;i++)
  18.            {
  19.                         Polymorpysim(a.get(i));
  20.                         System.out.println();
  21.            }
  22.            //formation 2
  23.            b.get(0).peymant();
  24.            out.println();
  25.            b.get(1).peymant();
  26.            out.println();
  27.            //----------------------------------------------
  28.            out.print("MENU\n"+
  29.                                                 "1.Salary\n"+
  30.                                                 "2.Hourly\n");
  31.                         out.print("\nYou can pick menu :");
  32.                         int menu=sc.nextInt();
  33.                 if(menu==1){
  34.                         int i;
  35.                         Scanner sc=new Scanner(System.in);
  36.                         out.print("MENU\n"+
  37.                                                 "0.Insert data\n"+
  38.                                                 "1.Search data\n"+
  39.                                                 "2.Edit data\n");
  40.                         out.print("\nYou can pick menu :");
  41.                         i=sc.nextInt();
  42.                         int ID;
  43.                         String Name;
  44.                         double money;
  45.                
  46.                                 if(i==0)
  47.                                 {
  48.                                         out.println("=========Insert data=========");
  49.                                         out.print("pls enter ID: ");
  50.                                         ID=sc.nextInt();
  51.                                         out.print("pls enter Name:");
  52.                                         Name=sc.next();
  53.                                         out.print("pls enter money :");
  54.                                         money=sc.nextDouble();
  55.                                         a.add(new salary(ID,Name,money));
  56.                                
  57.                                 }
  58.                                 else if(i==1)
  59.                                 {
  60.                                         int k;
  61.                                         out.println("=========Search data=========");
  62.                                         out.print("Menu\n"+
  63.                                                                           "1.ID\n"+
  64.                                                                           "2.Name\n"+
  65.                                         "pls enter number pick number:");
  66.                                         k=sc.nextInt();
  67.                                         if(k==1)
  68.                                         {
  69.                                                 out.print("enter ID:");
  70.                                                 ID=sc.nextInt();
  71.                                                 for(int j=0;j<a.size();j++)
  72.                                                 {
  73.                                                         if(a.get(j).id==ID)
  74.                                                         {
  75.                                                                 out.println("TRUE");
  76.                                                                 break;
  77.                                                         }
  78.                                                         else
  79.                                                         {
  80.                                                                 out.println("falase");
  81.                                                                 break;
  82.                                                         }
  83.                                                 }
  84.                                         }
  85.                                         else if(k==2)
  86.                                         {
  87.                                                 out.print("enter Name:");
  88.                                                 Name=sc.next();
  89.                                                 for(int j=0;j<a.size();j++)
  90.                                                 {
  91.                                                         if(a.get(j).name.equals(Name))
  92.                                                         {
  93.                                                                 out.println("TRUE");
  94.                                                                 break;
  95.                                                         }
  96.                                                         else
  97.                                                         {
  98.                                                                 out.println("falase");
  99.                                                                 break;
  100.                                                         }
  101.                                                 }
  102.                                         }
  103.                                 }
  104.  
  105.                        
  106.                         else if(i==2)
  107.                         {
  108.                                 int position;
  109.                                 out.println("=========Edit data=========");
  110.                                 out.print("pls enter Position: ");
  111.                                 position=sc.nextInt();
  112.                                 out.print("pls enter ID: ");
  113.                                 ID=sc.nextInt();
  114.                                 out.print("pls enter Name:");
  115.                                 Name=sc.next();
  116.                                 out.print("pls enter money :");
  117.                                 money=sc.nextDouble();
  118.                                 a.add(position,new salary(ID,Name,money));
  119.                                
  120.                                
  121.                         }
  122.                 }
  123.                 else if (menu==2)
  124.                 {
  125.                         int i;
  126.                         Scanner sc=new Scanner(System.in);
  127.                                                 out.print("MENU\n"+
  128.                                                 "0.Insert data\n"+
  129.                                                 "1.Search data\n"+
  130.                                                 "2.Edit data\n");
  131.                         out.print("\nYou can pick menu :");
  132.                         i=sc.nextInt();
  133.                         int ID;
  134.                         String Name;
  135.                         double Hours;
  136.                
  137.                                 if(i==0)
  138.                                 {
  139.                                         out.println("=========Insert data=========");
  140.                                         out.print("pls enter ID: ");
  141.                                         ID=sc.nextInt();
  142.                                         out.print("pls enter Name:");
  143.                                         Name=sc.next();
  144.                                         out.print("pls enter hour:");
  145.                                         Hours=sc.nextDouble();
  146.                                         a.add(new salary(ID,Name,Hours));
  147.                                
  148.                                 }
  149.                                 else if(i==1)
  150.                                 {
  151.                                         int k;
  152.                                         out.println("=========Search data=========");
  153.                                         out.print("Menu\n"+
  154.                                                                           "1.ID\n"+
  155.                                                                           "2.Name\n"+
  156.                                         "pls enter number pick number:");
  157.                                         k=sc.nextInt();
  158.                                         if(k==1)
  159.                                         {
  160.                                                 out.print("enter ID:");
  161.                                                 ID=sc.nextInt();
  162.                                                 for(int j=0;j<a.size();j++)
  163.                                                 {
  164.                                                         if(a.get(j).id==ID)
  165.                                                         {
  166.                                                                 out.println("TRUE");
  167.                                                                 break;
  168.                                                         }
  169.                                                         else
  170.                                                         {
  171.                                                                 out.println("falase");
  172.                                                                 break;
  173.                                                         }
  174.                                                 }
  175.                                         }
  176.                                         else if(k==2)
  177.                                         {
  178.                                                 out.print("enter Name:");
  179.                                                 Name=sc.next();
  180.                                                 for(int j=0;j<a.size();j++)
  181.                                                 {
  182.                                                         if(a.get(j).name.equals(Name))
  183.                                                         {
  184.                                                                 out.println("TRUE");
  185.                                                                 break;
  186.                                                         }
  187.                                                         else
  188.                                                         {
  189.                                                                 out.println("falase");
  190.                                                                 break;
  191.                                                         }
  192.                                                 }
  193.                                         }
  194.                                 }
  195.                        
  196.                         else if(i==2)
  197.                         {
  198.                                 int position;
  199.                                 out.println("=========Edit data=========");
  200.                                 out.print("pls enter Position: ");
  201.                                 position=sc.nextInt();
  202.                                 out.print("pls enter ID: ");
  203.                                 ID=sc.nextInt();
  204.                                 out.print("pls enter Name:");
  205.                                 Name=sc.next();
  206.                                 out.print("pls enter money hour:");
  207.                                 Hours=sc.nextDouble();
  208.                                 a.add(position,new salary(ID,Name,Hours));
  209.                                
  210.                                
  211.                         }
  212.                 }
  213.            
  214.         }
  215.         static void Polymorpysim(salary m)
  216.         {
  217.                 m.calculateExpense();
  218.                 m.peymant();  
  219.         }
  220.  
  221. }
  222.                
  223.  
  224. abstract class Employee
  225. {
  226.         int id;
  227.         String name;
  228.         void printDetail()
  229.         {
  230.                 out.println("ID : " + id);
  231.         out.println("Name : " + name);
  232.     }
  233.        
  234.         abstract void peymant();
  235.        
  236. }
  237. interface Expense
  238. {
  239.         public final double tax =0.05;
  240.         public abstract double calculateExpense();
  241. }
  242. class salary  extends Employee implements Expense
  243. {
  244.         double salarY;
  245.         salary(int id,String name,double salarY)
  246.         {
  247.                 this.id=id;
  248.                 this.name=name;
  249.                 this.salarY=salarY;
  250.         }
  251.         public double calculateExpense()
  252.         {
  253.                 if(salarY>15000)
  254.                 {
  255.                         return  salarY*tax;
  256.                 }
  257.                 else
  258.                 {
  259.                         return 0;
  260.                 }
  261.                
  262.     }
  263.                
  264.         public void peymant()
  265.         {
  266.                 double Netsalary=salarY-calculateExpense();
  267.                 printDetail();
  268.                 out.println("Salary : " + salarY);
  269.         out.println("Expense : " + calculateExpense());
  270.         out.println("Net Salary : " + Netsalary);
  271.         }
  272. }
  273. class Hourly extends Employee
  274. {
  275.         Scanner shit=new Scanner(System.in);
  276.         int hourRate;
  277.         Hourly(int id,String name,int hourRate)
  278.         {
  279.                 this.id=id;
  280.                 this.name=name;
  281.                 this.hourRate=hourRate;
  282.                
  283.         }
  284.         void peymant()
  285.         {
  286.                 printDetail();
  287.                 out.print("Enter Work Hour : ");
  288.                 int hour=shit.nextInt();
  289.                 /*for(int i=0;i<99;i++)
  290.                 {
  291.                         System.out.println("\n");
  292.                 }*/
  293.                 out.println("Hour Rate : " + hourRate);
  294.         out.println("Work Hours : " + hour);
  295.                 out.println("NetPayment: "+(hour*hourRate));
  296.                
  297.                
  298.         }
  299.        
  300.        
  301. }
Advertisement
Add Comment
Please, Sign In to add comment