PBLJ Experiment 2.4
PBLJ Experiment 2.4
Program: -
package LAB;
import java.io.*;
import java.util.*;
int id,age;
String name;
float salary;
long contact_no;
String email_id;
public Employee(int id, String name, int age, float salary, long contact_no, String
email_id)
{
this.id = id;
this.name = name;
this.age = age;
this.salary = salary;
this.contact_no = contact_no;
this.email_id = email_id;
}
@SuppressWarnings("unchecked")
public static void main(String[] args)
{
int id,age;
String name;
float salary;
long contact_no;
String email_id;
File f = null;
FileInputStream fis = null;
ObjectInputStream ois = null;
FileOutputStream fos = null;
ObjectOutputStream oos =null;
try{
}
catch(Exception exp){
System.out.println(exp);
}
do
{
System.out.println("\n*********Welcome to the Employee Management
System**********\n");
System.out.println("""
1). Add an Employee
2). Search for Employee
3). Edit Employee details
4). Delete Employee Details
5). Display all
6). EXIT
""");
System.out.println("Enter your choice : ");
int ch = sc.nextInt();
switch (ch) {
case 1 -> {
System.out.println("\nEnter the following details to ADD list:\n");
System.out.println("Enter ID :");
id = sc.nextInt();
System.out.println("Enter Name :");
name = sc.next();
System.out.println("Enter Age :");
age = sc.nextInt();
System.out.println("Enter Salary :");
salary = sc.nextFloat();
System.out.println("Enter Contact No :");
contact_no = sc.nextLong();
System.out.println("Enter Email-ID :");
email_id = sc.next();
al.add(new Employee(id, name, age, salary, contact_no, email_id));
display(al);
}
case 2 -> {
System.out.println("Enter the Employee ID to search :");
id = sc.nextInt();
int i = 0;
for (Employee e : al) {
if (id == e.id) {
System.out.println(e + "\n");
i++;
}
}
if (i == 0) {
System.out.println("\nEmployee Details are not available,
Please enter a valid ID!!");
}
}
case 3 -> {
System.out.println("\nEnter the Employee ID to EDIT the details");
id = sc.nextInt();
int j = 0;
for (Employee e : al) {
if (id == e.id) {
j++;
do {
int ch1 = 0;
System.out.println("""
}
System.out.println("\nYou have chosen EXIT !! Saving Files and
closing the tool.");
sc.close();
System.exit(0);
}
default -> System.out.println("\nEnter a correct choice from the
List :");
}
}
while(true);
}
}
Output: -