0% found this document useful (0 votes)
10 views3 pages

Employee Information Management App

The document describes an experiment that creates an application to save employee information like ID number, name, department, designation, salary details in arrays. The application takes user input for an employee ID and searches the arrays to find the matching employee and print their details including designation and calculated salary. If the ID is not found, a message is displayed indicating the same.

Uploaded by

Aman sehgal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

Employee Information Management App

The document describes an experiment that creates an application to save employee information like ID number, name, department, designation, salary details in arrays. The application takes user input for an employee ID and searches the arrays to find the matching employee and print their details including designation and calculated salary. If the ID is not found, a message is displayed indicating the same.

Uploaded by

Aman sehgal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

EXPERIMENT NO 1

NAME – PARAS GUPTA

UID – 20BCS5172

SECTION – 612 A

SUBJECT – PBLJ LAB

DATE – 23-08-2022

QUES -create an application to save the employee information in array.


Code –
import [Link].*;

public class QUES1


{
public static void main(String[] args) {
int emp_no[]= {1001,1002,1003,1004,1005,1006,1007};
String emp_name[]=
{"ASHISH","SUSHMA","RAHUL","CHAHAT","RANJAN","SUMAN","TANMAY"};
String join_date[]={"01/04/2009","23/08/2012 ","12/11/2008
","29/01/2013","16/07/2005","1/1/2000 ","12/06/2006"};
String design_code[]={"E","C","K","R","M","E","C"};
String dept[]={"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};

Scanner sc = new Scanner([Link]);


[Link]("enter the emp id - ");
int DA;
int salary;
String designation;
int n = [Link]();
int flag = 0;

for(int i =0;i<7;i++)
{
if(emp_no[i]==n)
{

flag =1;

switch(design_code[i]){

case "E":
DA = 20000;
designation="Engineer";
salary = basic[i]+HRA[i]+ DA-IT[i];
[Link]("EMP NO EMP NAME DEPARTMENT
DESIGNATION SALARY ");
[Link](emp_no[i]+" "+emp_name[i]+"
"+dept[i]+" "+designation+" "+salary);
break;

case "C":
DA = 32000;
designation="consultant";
salary = basic[i]+HRA[i]+ DA-IT[i];
[Link]("EMP NO EMP NAME DEPARTMENT
DESIGNATION SALARY ");
[Link](emp_no[i]+" "+emp_name[i]+"
"+dept[i]+" "+designation+" "+salary);
break;

case "K":
DA = 12000;
designation="clerk";
salary = basic[i]+HRA[i]+ DA-IT[i];
[Link]("EMP NO EMP NAME DEPARTMENT
DESIGNATION SALARY ");
[Link](emp_no[i]+" "+emp_name[i]+"
"+dept[i]+" "+designation+" "+salary);
break;

case "R":
DA = 15000;
designation="receptionist";
salary = basic[i]+HRA[i]+ DA-IT[i];
[Link]("EMP NO EMP NAME DEPARTMENT
DESIGNATION SALARY ");
[Link](emp_no[i]+" "+emp_name[i]+"
"+dept[i]+" "+designation+" "+salary);
break;

case "M":
DA = 40000;
designation="Manager";
salary = basic[i]+HRA[i]+ DA-IT[i];
[Link]("EMP NO EMP NAME DEPARTMENT
DESIGNATION SALARY ");
[Link](emp_no[i]+" "+emp_name[i]+"
"+dept[i]+" "+designation+" "+salary);
break;

if(flag==0)
{
[Link]("emp id "+n+" doesnot exist ");
}
}
}

Output –

Common questions

Powered by AI

The switch-case structure is crucial for associating designation codes with respective designations and determining the Dearness Allowance (DA) for salary calculations. For each employee, based on their design_code, the switch-case assigns the appropriate designation (e.g., Engineer, Consultant, Clerk) and defines the DA amount. The total salary is then calculated by summing the basic salary, HRA, DA, and subtracting the IT. This approach simplifies managing multiple designations and ensures clear alignment between codes and roles in the application .

The application includes basic use of Java's Scanner class for user input but underutilizes other java.util package features that could enhance functionality. For instance, using data structures such as HashMaps could pair designation codes with DA values more dynamically and flexibly than the current array system. This would simplify access and updates for designation logic and enhance scalability without extensive code changes .

Hard-coded DA values in the switch-case structure limit the application's adaptability to changes in DA policies or organizational data needs. Any changes would require modifying the code itself and recompiling the application, making it less flexible and increasing maintenance effort. A more adaptable design could involve mapping designations to DA values externally, possibly in a configuration file or database, which could be updated without altering the application's core code .

The primary purpose of the application is to store and manage employee information using arrays. Employee data is structured in parallel arrays, each representing different attributes such as employee number (emp_no), name (emp_name), joining date (join_date), designation code (design_code), department name (dept), basic salary (basic), HRA (HRA), and IT deductions (IT). A lookup is performed based on the employee number, and the associated information is processed to calculate the total salary, which is then displayed along with other employee details .

Encapsulating employee data using class-based design significantly overcomes the limitations evident in the current array-based setup by ensuring that all employee-related attributes are bundled within a single entity, preserving data integrity. This approach minimizes the risk of mismatched indices, simplifies data management, and enforces consistency. Moreover, it supports controlled access through methods, allowing for robust validation and transformation logic which the current design cannot efficiently implement. This encapsulation aligns more closely with OOP principles of data hiding and abstraction, making the program more modular, flexible, and maintainable .

Using parallel arrays in the application offers simplicity, which makes it easy to group related employee data and efficiently index attributes using a common index. This design allows straightforward iteration and lookup functionalities. However, the drawbacks include the challenges in maintaining data integrity, as adding or removing employee records requires synchronized updates across all arrays. Furthermore, it lacks the ability to represent complex relationships and can lead to errors if not carefully managed, such as misalignment of indices. A more robust approach might use an array of objects or a collection like a list to encapsulate employee data more securely and flexibly .

The application manages invalid employee ID inputs by setting a flag to zero initially. If the ID is not found in the emp_no array after iteration, it prints a message: "emp id [input id] doesnot exist". While this provides basic feedback, it could be improved by offering more detailed guidance on valid input formats or suggesting next steps, improving user experience by reducing confusion and helping guide user actions effectively .

To enhance scalability and ease of maintenance, I'd recommend refactoring the application to use classes and objects, encapsulating employee data within an Employee class. This would allow dynamic resizing of employee data storage using collections like ArrayLists that can grow as needed. Additionally, using Enum types for designations could improve code readability and reduce errors associated with hard-coded strings. Implementing a database or file storage system would allow persistent data storage, overcoming the constraints of in-memory arrays .

The design_code array plays a crucial role in linking employee attributes to specific designations and determining their salary structure through the switch-case logic. Each employee's design_code identifies their role, which associates them with a particular designation, DA, and hence influences salary computation. This integration allows the application to dynamically calculate each employee's salary based on their role, pulling together their basic pay, HRA, IT deduction, and the role-specific DA value for comprehensive salary calculation and display alongside their departmental information .

Storing salary data in arrays allows for predictable and fast access times given its contiguous memory allocation, which benefits computational performance through efficient iteration during operations such as calculations or searches. However, arrays have fixed sizes, which could lead to memory inefficiencies, especially if the allowed array size doesn't match the number of employees. This rigidity can lead to unused space or require array reallocation if more employees need to be added, impacting memory efficiency negatively .

You might also like