This document describes an assignment to create an employee management program with two classes - Employee and Client. The Employee class contains data members like name, ID, job details, and methods to set, update, and search employee information. The Client class contains the main method with a menu to add, update, delete or search employees stored in an array. It also handles file serialization to save employee records.
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
ACP Java Assignment.pdf
1. ADVANCE COMPUTER PROGRAMMING
Submitted by
MUHAMMADSOHAIB
593-FBAS/BSIT4/F20
Submitted to
Dr. Syed Saqlain
DCSIT, FBAS
Department of Computer Science and Software Engineering
INTERNATIONAL ISLAMIC UNIVERSITY
ISLAMABAD
Semester Fall 2022
2. : Assignment No.1
Question:
Build a program which should have two classes Employee and Client. Employee should be in
package ACP.Employee while Client class should be in ACP.Client. Employee class should
have the following data members and Functionalities
Data members:
Employee Name
Father name
Emp ID (Number)
Job Category (Teacher, Officer, Staff, Labour)
Date of birth (Date)
Education (Matric, FSc, BS, MS, PhD)
Pay scale (number)
NIC (String)
Functionalities:
SetEmpInformation
UpdateEmpInformation
DeleteEmpInformation
Search and View Emp record by
Emp ID
Employee Name
Age
Job Catagory
Client class should have main function where it may have capacity of maximum 50 Employee
records and You are only allowed to use arrays(list is not allowed).
User should be given choice whether to
Add New Employee record
Update Employee Information
Delete Employee Record
Search & view Employee
BY Emp ID
By Employee Name
By Age
By Job Catagory
Choices may be taken by using Input Message dialogs.
3. When user selects Add New Employee record, It must be kept in mind that no Teacher can have
education lower than MS while No Officer can have lower than BS, No Staff can be lesser
education than FSc and Labour should be with at least Matric Education. In the same manner for
the Teacher pay scale can not be lesser than 18 while for the officer it cant be lesser than 17, the
staff should be in between 11 and 16 and the pay scale for labour will be in between 1 and 10.
On update Employee Information, only education payscale and Job category can be updated.
When program is closed all the records should be saved into the file named as EmpDB.dat. all
the objects must be serialized into the file. When the program starts if file EmpDB.dat is already
present then user should have all required choices to apply on records available in file.
You will use java serialization to implement object serialization.
Note: Inputs should be taken by using Input dialogs and View should be by using
showMessageDialog.
Emp ID should be unique and should not be set by user. It should be automatically
assigned and Emp ID should start from 9000.
----------------------------------------------
Class Employee
package ACP.Employee;
import javax.swing.*;
import java.io.Serializable;
public class Employee implementsSerializable
{
public static int id = 9000;
private String empName;
private String empFname;
private int empId= id;
12. return-1;
}
public voiddisplay()
{
JOptionPane.showMessageDialog(null,"Employee Information: nName : "+empName+"nFather
Name : "+empFname+"nID: "+empId+"nJobCategory:"+jobCategory+"nEducation:
"+education+"nPayscale :"+payScale+"nCNIC:"+NIC);
}
}
------------------------------------------------------------
Class Client
package ACP.Client;
import javax.swing.JOptionPane;
import ACP.Employee.Employee;
import java.io.*;
public class Client
{
public static void main(String[] args) {
Employee[] A = new Employee[50];
int n = -1;
File empdb = new File("EmpDB.dat");
if(empdb.exists())
{
13. try
{
FileInputStream fis= new FileInputStream(empdb);
ObjectInputStream ois = new ObjectInputStream(fis);
A = (Employee[]) ois.readObject();
for (int i = 0; i < A.length; i++)
{
if(A[i] != null)
{
n++;
}
else break;
}
ois.close();
fis.close();
}catch(Exception e)
{
e.printStackTrace();
}
}
do
{
int choice = Integer.parseInt( JOptionPane.showInputDialog("MAIN MENUn1 Add an
Employeen2 Update an Employee'sInformationn3 Delete an Employee's Informationn4 Search and
View Employeesn5 Quit"));
switch(choice)
{
case 1:
14. {
if(n+1 != A.length)
{
n++;
A[n] = new Employee();
A[n].setEmpInformation();
}
else JOptionPane.showMessageDialog(null, "No space for new Employee !");
break;
}
case 2:
{
if(n != -1)
{
int id = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter the ID of employee
you want to Update : ")) ;
int index = Employee.search(A,n,id,null,-1,null);
if(index != -1)
{
A[index].updateEmpInformation();
}
else JOptionPane.showMessageDialog(null, "No Employee with such ID found !");
}
else JOptionPane.showMessageDialog(null, "Add an Employee first !");
15. break;
}
case 3:
{
if(n != -1)
{
int id = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter the ID of employee
you want to Remove : ")) ;
int index = Employee.search(A,n,id,null,-1,null);
if(index != -1)
{
n = Employee.deleteEmpInformation(A,n,index);
}
else JOptionPane.showMessageDialog(null, "No Employee with such ID found !");
}
else JOptionPane.showMessageDialog(null, "Add an Employee first !");
break;
}
case 4:
{
if(n != -1)
{
choice = Integer.parseInt( JOptionPane.showInputDialog("nttSearch Menunt1 <-
Search by Employee's IDnt2 <- Search by Employee's Nament3 <- Search by Employee's Agent4 <-
Search by Employee's Job categorynt5 <- Go back to Main menu"));
switch(choice)
16. {
case 1:
{
int id = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter the ID of
employee you want to Search : ")) ;
int index = Employee.search(A,n,id,null,-1,null);
if(index != -1)
{
A[index].display();
}
else JOptionPane.showMessageDialog(null, "No Employee with such ID found !");
break;
}
case 2:
{
String name = JOptionPane.showInputDialog(null, "Enter the Name of employee you
want to Search : ");
int index = Employee.search(A,n,-1,name,-1,null);
if(index != -1)
{
A[index].display();
}
else JOptionPane.showMessageDialog(null, "No Employee with such Name found
!");
break;
}
case 3:
{
17. int age = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter the Age of
employee you want to Search : "));
int index = Employee.search(A,n,-1,null,age,null);
if (index != -1)
{
A[index].display();
}
else JOptionPane.showMessageDialog(null, "No Employee with such Age found !");
break;
}
case 4:
{
String jobCategory = JOptionPane.showInputDialog(null, "Enterthe Job Category of
Employee you want to search : ");
int index = Employee.search(A, n, -1, null, -1, jobCategory);
if(index != -1)
{
A[index].display();
}
else JOptionPane.showMessageDialog(null, "No Employee with such Job Category
found !");
break;
}
case 5:
{
break;
}
}
}
18. else JOptionPane.showMessageDialog(null, "Add an Employee first !");
break;
}
case 5:
{
try
{
FileOutputStream fos = new FileOutputStream(empdb);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(A);
oos.close();
fos.close();
return;
}catch(Exception e)
{
e.printStackTrace();
}
break;
}
default: {
JOptionPane.showMessageDialog(null, "Please Choose a Valid Option !");
break; }
}
}while(true); }
}
----------------------------THEEND----------------------------