0% found this document useful (0 votes)
26 views

HarshJAVA Worksheet 1

The document describes a Java program that stores employee information like ID number, name, joining date, designation, department, salary and other details in an array. The program accepts an employee ID from the command line and searches the array to display the matching employee's details such as name, department, designation and calculated salary. The output shows the formatted details of the employee with the given ID if found, or a message that no matching employee was found.

Uploaded by

harshasingha450
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

HarshJAVA Worksheet 1

The document describes a Java program that stores employee information like ID number, name, joining date, designation, department, salary and other details in an array. The program accepts an employee ID from the command line and searches the array to display the matching employee's details such as name, department, designation and calculated salary. The output shows the formatted details of the employee with the given ID if found, or a message that no matching employee was found.

Uploaded by

harshasingha450
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Experiment1.

Student Name: Harsh Vardhan Singh UID: 21BCS11789


Branch:BE-CSE Section/Group:901/B
Semester: 6 Date of Performance:18-01-2024
Subject Name: Java Lab
Subject Code:21CSH-319

1. Aim: Create a application to save the employee information using arrays

2. Objective: Given 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 details

3. Algo. /Approach and output:


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
class Employee {
int empNo;
String empName;
Date joinDate;
char desigCode;
String department;
double basic;
double hra;
double it;
public Employee(int empNo, String empName, String joinDate, char
desigCode, String department, double basic, double hra, double it) throws
ParseException {
this.empNo = empNo;
this.empName = empName;
this.joinDate = new
SimpleDateFormat("dd/MM/yyyy").parse(joinDate);
this.desigCode = desigCode;
this.department = department;
this.basic = basic;
this.hra = hra;
this.it = it;
}
public double calculateSalary() {
double da = getDA();
return basic + hra + da - it;
}
public String getDesignation() {
switch (desigCode) {
case 'e':
return "Engineer";
case 'c':
return "Consultant";
case 'k':
return "Clerk";
case 'r':
return "Receptionist";
case 'm':
return "Manager";
default:
return "Unknown";
}
}
private double getDA() {
switch (desigCode) {
case 'e':
return 20000;
case 'c':
return 32000;
case 'k':
return 12000;
case 'r':
return 15000;
case 'm':
return 40000;
default:
return 0;
}
}
}
public class Project1 {
public static void main(String[] args) {
if (args.length != 1) {
System.out.println("Usage: java Project1 <EmpNo>");
return;
}
int empNo = Integer.parseInt(args[0]);
Employee[] employees = new Employee[7];
try {
employees[0] = new Employee(1001, "Ashish", "01/04/2009", 'e',
"R&D", 20000, 8000, 3000);
employees[1] = new Employee(1002, "Shashi", "23/08/2012", 'c',
"PM", 30000, 12000, 9000);
employees[2] = new Employee(1003, "Rahul", "12/11/2008", 'k',
"Acct", 10000, 8000, 1000);
employees[3] = new Employee(1004, "Chahat", "29/01/2013", 'r',
"Front Desk", 12000, 6000, 2000);
employees[4] = new Employee(1005, "Ranjan", "16/07/2005", 'm',
"Engg", 50000, 20000, 20000);
employees[5] = new Employee(1006, "Suman", "01/01/2000", 'e',
"Manufacturing", 23000, 9000, 4400);
employees[6] = new Employee(1007, "Tanmay", "12/06/2006", 'c',
"PM", 29000, 12000, 10000);
} catch (ParseException e) {
e.printStackTrace();
}
boolean found = false;
for (Employee employee : employees) {
if (employee != null && employee.empNo == empNo) {
found = true;
System.out.println("Emp No.\tEmp Name\tDepartment\
tDesignation\tSalary");
System.out.println(employee.empNo + "\t" + employee.empName
+ "\t" + employee.department + "\t" + employee.getDesignation() + "\t" +
employee.calculateSalary());
break;
}
}
if (!found) {
System.out.println("There is no employee with empid : " + empNo);
}
}
}

Output:

You might also like