sourav8256

Untitled

Mar 25th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.13 KB | None | 0 0
  1.  
  2. /*
  3.  *
  4.  * created by Sourav Mandal
  5.  * 3/2/2019 10:23pm
  6.  * jdk version jdk_1.8
  7.  *
  8.  *
  9.  */
  10.  
  11.  
  12.  
  13. public class EmpInfo {
  14.    
  15.    
  16.    
  17.     CommandParser commandParser;
  18.     EmployeeHandler employeeHandler;
  19.     Database database;
  20.    
  21.    
  22.    
  23.     public static void main(String[] args){
  24.         new EmpInfo(args);
  25.     }
  26.    
  27.    
  28.     public EmpInfo(String[] args) {    
  29.         commandParser = new CommandParser(args);
  30.         database = new Database();
  31.         employeeHandler = new EmployeeHandler();
  32.        
  33.         Output output = employeeHandler.getOutput(commandParser.empNo);
  34.         if(output!=null) {
  35.             output.printToConsole();
  36.         } else {
  37.             System.out.println("There is no employee with empid:"+commandParser.empNo);
  38.         }
  39.     }
  40.    
  41.    
  42.     public class CommandParser{
  43.        
  44.         int empNo;
  45.        
  46.         public CommandParser(String[] args) {
  47.             this.empNo = Integer.parseInt(args[0]);
  48.         }
  49.        
  50.     }
  51.    
  52.    
  53.    
  54.     public class Employee{
  55.        
  56.         int empNo;
  57.         String empName;
  58.         String joinDate;
  59.         String designationCode;
  60.         String department;
  61.         int basic;
  62.         int hra;
  63.         int it;
  64.        
  65.         public Employee(int empNo,String empName,String joinDate,String designationCode,String department,int basic,int hra,int it) {
  66.             this.empNo = empNo;
  67.             this.empName = empName;
  68.             this.joinDate = joinDate;
  69.             this.designationCode = designationCode;
  70.             this.department = department;
  71.             this.basic = basic;
  72.             this.hra = hra;
  73.             this.it = it;
  74.         }
  75.        
  76.     }
  77.    
  78.    
  79.     public class Designation{
  80.         String designationCode;
  81.         String designation;
  82.         int da;
  83.        
  84.         public Designation(String designationCode,String designation,int da) {
  85.             this.designationCode = designationCode;
  86.             this.designation = designation;
  87.             this.da = da;
  88.         }
  89.     }
  90.    
  91.    
  92.     public class Database{
  93.        
  94.         Employee[] employees = {
  95.             new Employee(1001,"Ashish","01/04/2009","e","R&D",20000,800,3000),
  96.             new Employee(1002,"Sushma","23/08,2012","c","PM",30000,12000,9000),
  97.             new Employee(1003,"Rahul","12/11/2008","k","Acct",10000,8000,1000),
  98.             new Employee(1004,"Chahat","29/01/2013","r","Front Desk",12000,6000,2000),
  99.             new Employee(1005,"Ranjan","16/07/2005","m","Engg",50000,20000,20000),
  100.             new Employee(1006,"Suman","1/1/2000","e","Manufacturing",23000,9000,4400),
  101.             new Employee(1007,"Tanmay","12/06/2006","c","PM",29000,12000,10000)
  102.         };
  103.        
  104.        
  105.         Designation[] designations = {
  106.             new Designation("e","Engineer",20000),
  107.             new Designation("c","Consultant",32000),
  108.             new Designation("k","Clerk",12000),
  109.             new Designation("r","Receptionist",15000),
  110.             new Designation("m","Manager",40000)
  111.         };
  112.        
  113.        
  114.         public Database() {
  115.            
  116.         }
  117.        
  118.        
  119.     }
  120.    
  121.    
  122.    
  123.     public class EmployeeHandler{
  124.         public EmployeeHandler() {
  125.            
  126.         }
  127.        
  128.        
  129.         Employee pickEmployee(int empNo) {
  130.            
  131.            
  132.             for(int i = 0;i<database.employees.length;i++) {
  133.                 if(database.employees[i].empNo == empNo) {
  134.                     return database.employees[i];
  135.                 }
  136.             }
  137.  
  138.             return null;
  139.            
  140.         }
  141.        
  142.        
  143.         Designation pickDesignation(String designationCode) {
  144.             switch(designationCode) {
  145.                 case "e" :
  146.                     return database.designations[0];
  147.                 case "c" :
  148.                     return database.designations[1];
  149.                 case "k" :
  150.                     return database.designations[2];
  151.                 case "r" :
  152.                     return database.designations[3];
  153.                 case "m" :
  154.                     return database.designations[4];
  155.                 default:
  156.                     return null;
  157.             }
  158.         }
  159.        
  160.        
  161.         Output getOutput(int empNo) {
  162.            
  163.             Employee employee = pickEmployee(empNo);
  164.            
  165.             if(employee == null) {
  166.                 return null;
  167.             }
  168.            
  169.            
  170.             Designation designation = pickDesignation(employee.designationCode);
  171.            
  172.  
  173.             return new Output(employee,designation);
  174.         }
  175.        
  176.        
  177.     }
  178.    
  179.    
  180.    
  181.     public class Output{
  182.        
  183.         Employee employee;
  184.         Designation designation;
  185.         int salary;
  186.        
  187.        
  188.         public Output(Employee employee,Designation designation) {
  189.                 this.employee = employee;
  190.                 this.designation = designation;
  191.                 this.salary = employee.basic + employee.hra + designation.da - employee.it;
  192.                
  193.         }
  194.        
  195.         void printToConsole(){
  196.             System.out.println("Emp No.\t\t\t\tEmp Name\t\t\tDepartment\t\t\t\tDesignation\t\t\t\tSalary");
  197.             System.out.println(employee.empNo+"\t\t\t\t"+employee.empName+"\t\t\t\t"+employee.department+"\t\t\t\t"+designation.designation+"\t\t\t\t"+salary);
  198.         }
  199.        
  200.     }
  201.  
  202. }
Add Comment
Please, Sign In to add comment