DEPARTMENT OF
COMPUTER SCIENCE &
Experiment - 1
Student Name: UID: 22BCS
Branch: Be-CSE Section/Group:22BCS
Semester: 6th Date of Performance:10/01/25
Subject Name: PBLJ with lab Code: 22CSH-359
1. Aim: Create an application to save the employee information using arrays.
2. Objective: The objective of this experiment is to develop a Java application that
stores employee data using arrays, retrieves specific details based on user input,
and calculates employee salaries dynamically. The application utilizes
conditional logic, such as loops and switch-case, to determine the employee's
designation and related allowances, demonstrating the practical implementation
of basic programming concepts in Java.
3. Implementation/Code:
import java.util.Scanner;
public class employee {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int []empNo={1001,1002,1003, 1004, 1005, 1006, 1007};
String []empName =
{"Ashish","Sushma","Rahul","Chahat","Ranjan","Suman","Tanmay"};
char[] desigCode = {'e', 'c', 'k', 'r', 'm', 'e', 'c'};
String[] department = {"R&D", "PM", "Acct", "Front Desk", "Engg",
"Manufacturing", "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 the id to find data: ");
int empId=sc.nextInt();
boolean found=false;
DEPARTMENT OF
COMPUTER SCIENCE &
for (int i=0;i<empNo.length;i++) {
if(empNo[i]==empId) {
found=true;
String designation="";
int da=0;
switch(desigCode[i]){
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;
default:
designation="Unknown";
da=0;
}
int salary=basic[i]+hra[i]+da-it[i];
System.out.println("Emp No.\tEmp Name\tDepartment\tDesignation\
tSalary");
System.out.println(empNo[i] + " " + empName[i] + " "+
department[i] + " " + designation + " " + salary);
// System.out.printf("%d\t%s\t\t%s\t\t%s\t\t%d\n", empNo[i], empName[i],
DEPARTMENT OF
COMPUTER SCIENCE &
department[i], designation, salary);
break;
}
}
if(!found){
System.out.println("There is no employee with empid: " +empId);
}
}
}
4. Output:
5. Learning Outcome:
1. Understood how to use arrays to store and retrieve structured data.
2. Learned the application of switch-case for conditional logic.
3. Gained experience in calculating and displaying output in a formatted
manner using Java.
4. Improved problem-solving skills by handling scenarios like invalid input.
5. Developed skills to handle invalid inputs and provide appropriate
feedback to the user.