Advertisement
stronk_8s

employee

Mar 3rd, 2024
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.92 KB | Source Code | 0 0
  1. /*
  2.  * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
  3.  * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template
  4.  */
  5. package company;
  6.  
  7. /**
  8.  *
  9.  * @author urvil
  10.  */
  11. import java.util.*;
  12. public class Company extends employee{
  13.  
  14.     /**
  15.      * @param args the command line arguments
  16.      */
  17.     public static void main(String[] args) {
  18.         int choice;
  19.         String s;
  20.         ArrayList<employee> a1 = new ArrayList<employee>();
  21.         Scanner sc = new Scanner(System.in);
  22.         do
  23.         {
  24.             System.out.println("1.Add");
  25.             System.out.println("2.Display");
  26.             System.out.println("3.Search position");
  27.             System.out.println("4.Search employee");
  28.             System.out.println("5.Search OG");
  29.             System.out.println("6.Exit");
  30.             choice = sc.nextInt();
  31.             sc.nextLine();
  32.             switch(choice){
  33.                 case 1:
  34.                     employee e = new employee();
  35.                     a1.add(e);
  36.                     break;
  37.                    
  38.                 case 2:
  39.                     for(employee e1:a1)
  40.                         e1.display();
  41.                     break;
  42.                    
  43.                 case 3:
  44.                    
  45.                     System.out.println("Enter position");
  46.                     s=sc.nextLine();
  47.                     for(employee e1:a1)
  48.                         if(e1.getType().equals(s))
  49.                             e1.display();
  50.                     break;
  51.                    
  52.                 case 4:
  53.                    
  54.                     System.out.println("Enter name");
  55.                     s=sc.nextLine();
  56.                     for(employee e1:a1)
  57.                         if(e1.getName().equals(s))
  58.                             e1.display();
  59.                     break;
  60.                    
  61.                 case 5:
  62. //                    System.out.println("id\tname\tage\ttype\tsalary");
  63. //                    for(employee e1:a1)
  64. //                        if(e1.getAge()>30 && e1.getAge()<60)
  65. //                            e1.display();
  66.                     break;
  67.                    
  68.                 default:
  69.                     System.out.println("invalid");
  70.                     break;
  71.             }
  72.         }while(choice!=6);
  73.     }
  74.    
  75. }
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92. /*
  93.  * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
  94.  * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
  95.  */
  96. package company;
  97.  
  98. /**
  99.  *
  100.  * @author urvil
  101.  */
  102. import java.util.*;
  103.  
  104. abstract class variables{
  105.     public String name,type;
  106.     public int id,jy,exp;
  107.     public double salary,bonus,total;
  108.    
  109.     Calendar calendar = new GregorianCalendar();    
  110.     int year = calendar.get(Calendar.YEAR);
  111. }
  112.  
  113. interface functions{
  114.     public abstract String getType();
  115.     public abstract String getName();
  116.     public abstract int getjy();
  117.     public abstract void display();
  118. }
  119.  
  120. public class employee extends variables implements functions {
  121.  
  122.     Scanner sc = new Scanner(System.in);
  123.    
  124.     public employee()
  125.     {
  126.         System.out.println("Enter Id");
  127.         id = sc.nextInt();
  128.         sc.nextLine();
  129.        
  130.         System.out.println("Enter name");
  131.         name = sc.nextLine();
  132.        
  133.         System.out.println("Enter job position(m,k,c)");
  134.         type = sc.nextLine();
  135.        
  136.         System.out.println("Enter jy");
  137.         jy = sc.nextInt();
  138.         sc.nextLine();
  139.        
  140.         System.out.println("Enter salary");
  141.         salary = sc.nextDouble();
  142.        
  143.        
  144.         if(type.equals("m"))
  145.             total += salary*0.1;
  146.         else if(type.equals("k"))
  147.             total += salary*0.06;
  148.         else
  149.             total = salary;
  150.        
  151.         exp = year-jy;
  152.        
  153.         if(exp>5 && exp<15)
  154.         {
  155.             bonus = 10000;
  156.             total+=bonus;
  157.         }
  158.         else if(exp>15 && exp<25)
  159.         {
  160.             bonus = 20000;
  161.             total+=bonus;
  162.         }
  163.         else if(exp>25 && exp<35)
  164.         {
  165.             bonus = 30000;
  166.             total+=bonus;
  167.         }
  168.         else
  169.         {
  170.             bonus = 40000;
  171.             total+=bonus;
  172.         }
  173.        
  174.     }
  175.    
  176.     @Override
  177.     public String getType() {
  178.         return type;
  179.     }
  180.  
  181.     @Override
  182.     public String getName() {
  183.         return name;
  184.     }
  185.  
  186.     @Override
  187.     public void display() {
  188.         System.out.println("id: "+id+"\n"
  189.                 +"name: "+name+"\n"
  190.                         +"jy: "+jy+"\n"
  191.                 +"type: "+type+"\n"
  192.                         +"salary: "+salary
  193.                 +"\n"+"exp: "+exp+"\n"
  194.                         +"total: "+total+
  195.                 "\n"+"bonus: "+bonus);
  196.     }
  197.  
  198.  
  199.     @Override
  200.     public int getjy() {
  201.         return jy;
  202.     }
  203.    
  204. }
  205.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement