Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- *
- * created by Sourav Mandal
- * 3/2/2019 10:23pm
- * jdk version jdk_1.8
- *
- *
- */
- public class EmpInfo {
- CommandParser commandParser;
- EmployeeHandler employeeHandler;
- Database database;
- public static void main(String[] args){
- new EmpInfo(args);
- }
- public EmpInfo(String[] args) {
- commandParser = new CommandParser(args);
- database = new Database();
- employeeHandler = new EmployeeHandler();
- Output output = employeeHandler.getOutput(commandParser.empNo);
- if(output!=null) {
- output.printToConsole();
- } else {
- System.out.println("There is no employee with empid:"+commandParser.empNo);
- }
- }
- public class CommandParser{
- int empNo;
- public CommandParser(String[] args) {
- this.empNo = Integer.parseInt(args[0]);
- }
- }
- public class Employee{
- int empNo;
- String empName;
- String joinDate;
- String designationCode;
- String department;
- int basic;
- int hra;
- int it;
- public Employee(int empNo,String empName,String joinDate,String designationCode,String department,int basic,int hra,int it) {
- this.empNo = empNo;
- this.empName = empName;
- this.joinDate = joinDate;
- this.designationCode = designationCode;
- this.department = department;
- this.basic = basic;
- this.hra = hra;
- this.it = it;
- }
- }
- public class Designation{
- String designationCode;
- String designation;
- int da;
- public Designation(String designationCode,String designation,int da) {
- this.designationCode = designationCode;
- this.designation = designation;
- this.da = da;
- }
- }
- public class Database{
- Employee[] employees = {
- new Employee(1001,"Ashish","01/04/2009","e","R&D",20000,800,3000),
- new Employee(1002,"Sushma","23/08,2012","c","PM",30000,12000,9000),
- new Employee(1003,"Rahul","12/11/2008","k","Acct",10000,8000,1000),
- new Employee(1004,"Chahat","29/01/2013","r","Front Desk",12000,6000,2000),
- new Employee(1005,"Ranjan","16/07/2005","m","Engg",50000,20000,20000),
- new Employee(1006,"Suman","1/1/2000","e","Manufacturing",23000,9000,4400),
- new Employee(1007,"Tanmay","12/06/2006","c","PM",29000,12000,10000)
- };
- Designation[] designations = {
- new Designation("e","Engineer",20000),
- new Designation("c","Consultant",32000),
- new Designation("k","Clerk",12000),
- new Designation("r","Receptionist",15000),
- new Designation("m","Manager",40000)
- };
- public Database() {
- }
- }
- public class EmployeeHandler{
- public EmployeeHandler() {
- }
- Employee pickEmployee(int empNo) {
- for(int i = 0;i<database.employees.length;i++) {
- if(database.employees[i].empNo == empNo) {
- return database.employees[i];
- }
- }
- return null;
- }
- Designation pickDesignation(String designationCode) {
- switch(designationCode) {
- case "e" :
- return database.designations[0];
- case "c" :
- return database.designations[1];
- case "k" :
- return database.designations[2];
- case "r" :
- return database.designations[3];
- case "m" :
- return database.designations[4];
- default:
- return null;
- }
- }
- Output getOutput(int empNo) {
- Employee employee = pickEmployee(empNo);
- if(employee == null) {
- return null;
- }
- Designation designation = pickDesignation(employee.designationCode);
- return new Output(employee,designation);
- }
- }
- public class Output{
- Employee employee;
- Designation designation;
- int salary;
- public Output(Employee employee,Designation designation) {
- this.employee = employee;
- this.designation = designation;
- this.salary = employee.basic + employee.hra + designation.da - employee.it;
- }
- void printToConsole(){
- System.out.println("Emp No.\t\t\t\tEmp Name\t\t\tDepartment\t\t\t\tDesignation\t\t\t\tSalary");
- 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);
- }
- }
- }
Add Comment
Please, Sign In to add comment