PBLJ Lab
Practical-1
Aim: Given a table containing information about employees of an organization,
develop a small java application, which accepts employee id from the command
prompt and displays output as certain details
Code:
import java.util.Scanner;
public class project1 {
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
int empId[] = {1001, 1002, 1003, 1004, 1005, 1006, 1007};
String empName[] = {"a", "b", "c", "d", "e", "f", "g"};
String joinDate[] = {"01/04/2009", "23/08/2012", "12/11/2008", "29/01/2013",
"16/07/2005",
"01/01/2000", "12/06/2006"};
char dCode[] = {'e','c','k','r','m','e','c'};
String Dept[] = {"r&d", "pm", "acct","front desk", "engg", "manufacturer",
"pm"};
int basic[] = {20000, 30000, 10000, 12000, 50000, 23000, 29000};
int hra[] = {8000, 12000, 8000, 6000, 20000, 9000, 12000};
int it[] = {3000, 9000, 1000, 2000, 20000, 4400, 10000};
System.out.println("Enter Employee Id to get salary");
int userInput = s.nextInt();
int index = 0;
int k=0;
// getting index
for (int i = 0; i< empId.length; i++)
17BCS2238 Page 1
This study source was downloaded by 100000834089164 from CourseHero.com on 05-14-2022 21:54:20 GMT -05:00
https://www.coursehero.com/file/54018276/java-1-38docx/
PBLJ Lab
{
if (empId[i] == userInput)
{
k=1;
break;
}
else
{
index ++;
}
}
//salary
if(k==0)
{
System.out.println("\nNo employee with that ID");
}
else
{
int da = 0;
char temp = dCode[index];
String dep = null;
switch(temp)
{
case 'e' : da = 20000;dep="Engineer";break;
case 'c' : da = 32000;dep="Consultant";break;
case 'k' : da = 12000;dep="Clerk";break;
case 'r' : da = 15000;dep="Receptionist ";break;
case 'm' : da = 40000;dep="Manager";break;
default: da = 0; break;}
17BCS2238 Page 2
This study source was downloaded by 100000834089164 from CourseHero.com on 05-14-2022 21:54:20 GMT -05:00
https://www.coursehero.com/file/54018276/java-1-38docx/
PBLJ Lab
int salary = basic[index] + hra[index] + da - it[index];
System.out.printf("%-10s %-10s %-15s %-15s %-10s\n","Emp
No.","Emp Name","Department"
,"Designation","Salary");
System.out.printf("%-10s %-10s %-15s %-15s %-
10s",userInput,empName[index],Dept[index],dep,salary);}}}
Output:
Enter Employee Id to get salary:1003
Emp No. Emp Name Department Designation Salary
1003 c acct Clerk 29000
Enter Employee Id to get salary:1062
No employee with that ID
17BCS2238 Page 3
This study source was downloaded by 100000834089164 from CourseHero.com on 05-14-2022 21:54:20 GMT -05:00
https://www.coursehero.com/file/54018276/java-1-38docx/
Powered by TCPDF (www.tcpdf.org)