Exp 2.4
Exp 2.4
Experiment 2.4
Student Name: Kaustabh Pal UID: 21BCS8791
Branch: CSE Section/Group: SC-905(B)
Semester: 6th Date of Performance: 07-03-24
Subject Name: JAVA LAB Subject Code: 21CSH-319
1. Aim: Create a menu-based Java application with the following options,1. Add
an Employee 2.Display All 3.Exit. If option 1 is selected, the application should
gather details of the employee like employee name, employee id, designation
and salary and store it in a file. If option 2 is selected, the application should
display all the employee details. If option 3 is selected the application should
exit.
3. Input/Apparatus:
Hardware Requirements:- Minimum 384MB RAM, 100 GB hard disk,
processor with 2.1 MHz
4. Procedure:
import java.io.*;
import java.util.LinkedList;
import java.util.Scanner;
int id;
String name;
String designation;
double salary;
this.id = id;
this.name = name;
this.designation = designation;
this.salary = salary;
@Override
return "Employee{" +
"id=" + id +
'}';
while (true) {
System.out.println("\n1. Add an Employee");
System.out.println("3. Exit");
switch (choice) {
case 1:
addEmployee(scanner);
break;
case 2:
displayAll();
break;
case 3:
System.out.println("Exiting...");
return;
default:
int id = scanner.nextInt();
employeeList.add(employee);
saveToFile();
readFromFile();
if (employeeList.isEmpty()) {
return;
System.out.println(employee);
oos.writeObject(employeeList);
} catch (IOException e) {
e.printStackTrace();
}
}
@SuppressWarnings("unchecked")
if (!file.exists()) return;
e.printStackTrace();
}
5. Output: