The following table containing information about employees of an organization, develop a small java application, which accepts employee id from the command prompt and displays
the following details as output:
Emp No Emp Name Department Designation and Salary
You may assume that the array is initialized with the following details:
Emp No. | Emp Name | Join Date | Desig Code | Dept | Basic | HRA | IT |
1001 | Ashish | 01/04/2009 | e | R&D | 20000 | 8000 | 3000 |
1002 | Sushma | 23/08/2012 | c | PM | 30000 | 12000 | 9000 |
1003 | Rahul | 12/11/2008 | k | Acct | 10000 | 8000 | 1000 |
1004 | Chahat | 29/01/2013 | r | Front Desk | 12000 | 6000 | 2000 |
1005 | Ranjan | 16/07/2005 | m | Engg | 50000 | 20000 | 20000 |
1006 | Suman | 1/1/2000 | e | Manu factur ing | 23000 | 9000 | 4400 |
1007 | Tanmay | 12/06/2006 | c | PM | 29000 | 12000 | 10000 |
Salary is calculated as Basic+HRA+DA-IT. (DA details are given in the Designation table)
Designation details :
Designation Code | Designation | DA |
e | Engineer | 20000 |
c | Consultant | 32000 |
k | Clerk | 12000 |
r | Receptionist | 15000 |
m | Manager | 40000 |
Use Switch-Case to print Designation in the output and to find the value of DA for a particular
employee.
O/P Expected:
1. Assuming that your class name is Hello, and you execute your code asjava Hello 1003, it should display the following output :
Emp No. Emp Name Department Designation Salary
1003 Rahul Acct Clerk 29000
2. java Hello 123
There is no employee with empid : 123
Solution:
public class Hello {
public static String Designation;
public static int DA;
public static void main(String args[]) {
if(args.length==0)
System.out.println("Please Provide Emp No.");
else {
int EmpNo =Integer.parseInt(args[0]);
String EmpName,Department;
int Basic,HRA,IT,Salary;
char DesigCode;
switch(EmpNo){
case 1001:
EmpName="Ashish";
DesigCode='e';
Department="R&D";
Basic=20000;
HRA=8000;
IT=3000;
getDesignation(DesigCode);
Salary =Basic+HRA+DA-IT;
System.out.println("Emp No.\t\tEmp Name\tDepartment\tDesignation\tSalary");
System.out.println(EmpNo+"\t\t"+EmpName+"\t\t"+Department+"\t\t"+Designation+"\t"+Salary);
break;
case 1002:
EmpName="Sushma";
DesigCode='c';
Department="PM";
Basic=30000;
HRA=12000;
IT=9000;
getDesignation(DesigCode);
Salary =Basic+HRA+DA-IT;
System.out.println("Emp No.\t\tEmp Name\tDepartment\tDesignation\tSalary");
System.out.println(EmpNo+"\t\t"+EmpName+"\t\t"+Department+"\t\t"+Designation+"\t"+Salary);
break;
case 1003:
EmpName="Rahul";
DesigCode='k';
Department="Acct";
Basic=10000;
HRA=8000;
IT=1000;
getDesignation(DesigCode);
Salary =Basic+HRA+DA-IT;
System.out.println("Emp No.\t\tEmp Name\tDepartment\tDesignation\tSalary");
System.out.println(EmpNo+"\t\t"+EmpName+"\t\t"+Department+"\t\t"+Designation+"\t\t"+Salary);
break;
case 1004:
EmpName="Chahat";
DesigCode='r';
Department="Front Desk";
Basic=12000;
HRA=6000;
IT=2000;
getDesignation(DesigCode);
Salary =Basic+HRA+DA-IT;
System.out.println("Emp No.\t\tEmp Name\tDepartment\tDesignation\tSalary");
System.out.println(EmpNo+"\t\t"+EmpName+"\t\t"+Department+"\t"+Designation+"\t"+Salary);
break;
case 1005:
EmpName="Ranjan";
DesigCode='m';
Department="Engg";
Basic=50000;
HRA=20000;
IT=20000;
getDesignation(DesigCode);
Salary =Basic+HRA+DA-IT;
System.out.println("Emp No.\t\tEmp Name\tDepartment\tDesignation\tSalary");
System.out.println(EmpNo+"\t\t"+EmpName+"\t\t"+Department+"\t\t"+Designation+"\t\t"+Salary);
break;
case 1006:
EmpName="Suman";
DesigCode='e';
Department="Manufacturing";
Basic=23000;
HRA=9000;
IT=4400;
getDesignation(DesigCode);
Salary =Basic+HRA+DA-IT;
System.out.println("Emp No.\t\tEmp Name\tDepartment\tDesignation\tSalary");
System.out.println(EmpNo+"\t\t"+EmpName+"\t\t"+Department+"\t"+Designation+"\t"+Salary);
break;
case 1007:
EmpName="Tanmay";
DesigCode='c';
Department="PM";
Basic=29000;
HRA=12000;
IT=10000;
getDesignation(DesigCode);
Salary =Basic+HRA+DA-IT;
System.out.println("Emp No.\t\tEmp Name\tDepartment\tDesignation\tSalary");
System.out.println(EmpNo+"\t\t"+EmpName+"\t\t"+Department+"\t\t"+Designation+"\t"+Salary);
break;
default:System.out.println("There is no employee with empid :"+EmpNo);
}
}
}
public static void getDesignation(char DesignationCode){
switch(DesignationCode){
case 'e': {
Designation="Engineer";
DA=20000;
break;
}
case 'c': {
Designation="Consultant";
DA=32000;
break;
}
case 'k': {
Designation="Clerk";
DA=12000;
break;
}
case 'r': {
Designation="Receptionist";
DA=15000;
break;
}
case 'm': {
Designation="Manager";
DA=40000;
break;
}
}
}
}