SlideShare a Scribd company logo
1 of 18
Download to read offline
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
: 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.
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;
private String jobCategory;
private String doB;
private String education;
private int payScale;
private String NIC;
private int age;
public Employee(){
id++;
empId= id;
}
public booleancheckInformation(StringcheckWhat)
{
//if checkingeducation
if(checkWhat.equals("education"))
{
if(jobCategory.equals("Teacher") ||jobCategory.equals("teacher"))
{
if(!education.equals("MS") &&!education.equals("PHD"))
{
JOptionPane.showMessageDialog(null,"TeacherCannothave educationlowerthanMS!");
return false;
}
}
else if(jobCategory.equals("Officer") ||jobCategory.equals("officer"))
{
if(education.equals("Matric") ||education.equals("FSC"))
{
JOptionPane.showMessageDialog(null,"Officercannothave educationlessthanBS !");
return false;
}
}
else if(jobCategory.equals("Staff") ||jobCategory.equals("staff"))
{
if(education.equals("Matric"))
{
JOptionPane.showMessageDialog(null,"Staff cannothave educationlessthanFSc !");
return false;
}
}
else if(jobCategory.equals("Labour") ||jobCategory.equals("labour"))
{
if(!education.equals("Matric"))
{
JOptionPane.showMessageDialog(null,"LabourMustbe Matric Pass !");
return false;
}
}
}
//if checkingpayscale
else if(checkWhat.equals("payscale"))
{
if(jobCategory.equals("Teacher") ||jobCategory.equals("teacher"))
{
if(payScale < 18)
{
JOptionPane.showMessageDialog(null,"TeacherCannothave payscale lowerthan18 !");
return false;
}
}
else if(jobCategory.equals("Officer") ||jobCategory.equals("officer"))
{
if(payScale < 17)
{
JOptionPane.showMessageDialog(null,"Officercannothave payscale lessthan 17 !");
return false;
}
}
else if(jobCategory.equals("Staff") ||jobCategory.equals("staff"))
{
if(payScale < 11 ||payScale > 16)
{
JOptionPane.showMessageDialog(null,"Staff cannothave payscale lessthan 11 or greater
than 16 !");
return false;
}
}
else if(jobCategory.equals("Labour") ||jobCategory.equals("labour"))
{
if(payScale < 1 || payScale > 10)
{
JOptionPane.showMessageDialog(null,"LabourMusthave payscale lessthan 11 and greater
then0 !");
return false;
}
}
}
returntrue;//if correcteducationor payscale
}
public voidsetEmpInformation()
{
booleancheckexception= false;
do
{
try
{
empName = JOptionPane.showInputDialog(null,"EnterEmployee Name :");
empFname = JOptionPane.showInputDialog(null,"EnterEmployee FatherName :");
jobCategory= JOptionPane.showInputDialog(null,"EnterJob Category
(teacher,officer,staff,labour) :");
booleancheck;
do
{
education= JOptionPane.showInputDialog(null,"Enter"+jobCategory+"'sEducation
(PHD,MS,BS,FSC,Matric) :");
check = checkInformation("education");
}while(!check);
do
{
payScale = Integer.parseInt(JOptionPane.showInputDialog(null,"Enter"+jobCategory+"'s
Payscale : "));
check = checkInformation("payscale");
}while(!check);
doB = JOptionPane.showInputDialog(null,"EnterEmployee Date of Birth (DD-MM-YYYY) :");
age = Integer.parseInt(doB.substring(6));
age = 2021 - age;
NIC= JOptionPane.showInputDialog(null,"EnterEmployee'sNIC:");
}catch(Exceptione)
{
checkexception= true;
JOptionPane.showMessageDialog(null,"invalidvalue enteredEnterValuesagain!");
}
checkexception= false;
}while(checkexception== true);
}
public voidupdateEmpInformation()
{
try
{
jobCategory= JOptionPane.showInputDialog(null,"Enternew JobCategory:");
booleancheck;
do
{
education= JOptionPane.showInputDialog(null,"Enter"+jobCategory+"'snew Education:");
check= checkInformation("education");
}while(!check);
do
{
payScale = Integer.parseInt(JOptionPane.showInputDialog(null,"Enter"+jobCategory+"'snew
Payscale : "));
check= checkInformation("payscale");
}while(!check);
}catch(Exceptione)
{
JOptionPane.showMessageDialog(null,"EnteraValid Value !");
}
}
public static int deleteEmpInformation(Employee [] A,intn,intindex)
{
for(int j = index;j < A.length-1;j++)
{
A[j] = A[j+1];
}
n--;
returnn;
}
public static int search(Employee[] A,intn, int id, String name, int age,String jobcat)
{
for(int i = 0; i <= n; i++)
{
if(id!= -1)
{
if(id == A[i].empId)
{
return i;
}
}
else if(name != null)
{
if(name.equals(A[i].empName))
{
return i;
}
}
else if(age != -1)
{
if(A[i].age == age)
{
return i;
}
}
else if(jobcat!= null)
{
if (jobcat.equals(A[i].jobCategory))
{
return i;
}
}
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())
{
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:
{
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 !");
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)
{
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:
{
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;
}
}
}
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----------------------------

More Related Content

Similar to ACP Java Assignment.pdf

Cis 407 i lab 4 of 7
Cis 407 i lab 4 of 7Cis 407 i lab 4 of 7
Cis 407 i lab 4 of 7
helpido9
 
Please be advised that there are four (4) programs just like this on.docx
Please be advised that there are four (4) programs just like this on.docxPlease be advised that there are four (4) programs just like this on.docx
Please be advised that there are four (4) programs just like this on.docx
lorindajamieson
 
Be sure to read all of Chapters 8 and 9 before starting this assignm.docx
Be sure to read all of Chapters 8 and 9 before starting this assignm.docxBe sure to read all of Chapters 8 and 9 before starting this assignm.docx
Be sure to read all of Chapters 8 and 9 before starting this assignm.docx
aman341480
 
1 Goals. 1. To use a text file for output and later for in.docx
1 Goals. 1. To use a text file for output and later for in.docx1 Goals. 1. To use a text file for output and later for in.docx
1 Goals. 1. To use a text file for output and later for in.docx
honey690131
 
Hi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdfHi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdf
fashioncollection2
 
Create a C# applicationYou are to create a class object called “Em.pdf
Create a C# applicationYou are to create a class object called “Em.pdfCreate a C# applicationYou are to create a class object called “Em.pdf
Create a C# applicationYou are to create a class object called “Em.pdf
feelingspaldi
 
3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf
3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf
3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf
alliedscorporation
 
Having issues with passing my values through different functions aft.pdf
Having issues with passing my values through different functions aft.pdfHaving issues with passing my values through different functions aft.pdf
Having issues with passing my values through different functions aft.pdf
rajkumarm401
 
Make sure to make a copy of the Google Doc for this lab into.pdf
Make sure to make a copy of the Google Doc for this lab into.pdfMake sure to make a copy of the Google Doc for this lab into.pdf
Make sure to make a copy of the Google Doc for this lab into.pdf
adityastores21
 

Similar to ACP Java Assignment.pdf (20)

Cis 407 i lab 4 of 7
Cis 407 i lab 4 of 7Cis 407 i lab 4 of 7
Cis 407 i lab 4 of 7
 
Please be advised that there are four (4) programs just like this on.docx
Please be advised that there are four (4) programs just like this on.docxPlease be advised that there are four (4) programs just like this on.docx
Please be advised that there are four (4) programs just like this on.docx
 
Typescript barcelona
Typescript barcelonaTypescript barcelona
Typescript barcelona
 
Be sure to read all of Chapters 8 and 9 before starting this assignm.docx
Be sure to read all of Chapters 8 and 9 before starting this assignm.docxBe sure to read all of Chapters 8 and 9 before starting this assignm.docx
Be sure to read all of Chapters 8 and 9 before starting this assignm.docx
 
1 Goals. 1. To use a text file for output and later for in.docx
1 Goals. 1. To use a text file for output and later for in.docx1 Goals. 1. To use a text file for output and later for in.docx
1 Goals. 1. To use a text file for output and later for in.docx
 
2. Create a Java class called EmployeeMain within the same project Pr.docx
 2. Create a Java class called EmployeeMain within the same project Pr.docx 2. Create a Java class called EmployeeMain within the same project Pr.docx
2. Create a Java class called EmployeeMain within the same project Pr.docx
 
Hi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdfHi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdf
 
Programming Primer EncapsulationVB
Programming Primer EncapsulationVBProgramming Primer EncapsulationVB
Programming Primer EncapsulationVB
 
Create a C# applicationYou are to create a class object called “Em.pdf
Create a C# applicationYou are to create a class object called “Em.pdfCreate a C# applicationYou are to create a class object called “Em.pdf
Create a C# applicationYou are to create a class object called “Em.pdf
 
3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf
3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf
3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf
 
OOP program questions with answers
OOP program questions with answersOOP program questions with answers
OOP program questions with answers
 
Having issues with passing my values through different functions aft.pdf
Having issues with passing my values through different functions aft.pdfHaving issues with passing my values through different functions aft.pdf
Having issues with passing my values through different functions aft.pdf
 
Form demoinplaywithmysql
Form demoinplaywithmysqlForm demoinplaywithmysql
Form demoinplaywithmysql
 
Make sure to make a copy of the Google Doc for this lab into.pdf
Make sure to make a copy of the Google Doc for this lab into.pdfMake sure to make a copy of the Google Doc for this lab into.pdf
Make sure to make a copy of the Google Doc for this lab into.pdf
 
Employee Management (CS Project for 12th CBSE)
Employee Management (CS Project for 12th CBSE)Employee Management (CS Project for 12th CBSE)
Employee Management (CS Project for 12th CBSE)
 
Programming Primer Encapsulation CS
Programming Primer Encapsulation CSProgramming Primer Encapsulation CS
Programming Primer Encapsulation CS
 
Oracle examples
Oracle examplesOracle examples
Oracle examples
 
Building l10n Payroll Structures from the Ground up
Building l10n Payroll Structures from the Ground upBuilding l10n Payroll Structures from the Ground up
Building l10n Payroll Structures from the Ground up
 
Creating Single Page Applications with Oracle Apex
Creating Single Page Applications with Oracle ApexCreating Single Page Applications with Oracle Apex
Creating Single Page Applications with Oracle Apex
 
Spawithapex0 150815075436-lva1-app6891
Spawithapex0 150815075436-lva1-app6891Spawithapex0 150815075436-lva1-app6891
Spawithapex0 150815075436-lva1-app6891
 

Recently uploaded

會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
中 央社
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
 

Recently uploaded (20)

OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptx
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
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;
  • 4. private String jobCategory; private String doB; private String education; private int payScale; private String NIC; private int age; public Employee(){ id++; empId= id; } public booleancheckInformation(StringcheckWhat) { //if checkingeducation if(checkWhat.equals("education")) { if(jobCategory.equals("Teacher") ||jobCategory.equals("teacher")) { if(!education.equals("MS") &&!education.equals("PHD")) { JOptionPane.showMessageDialog(null,"TeacherCannothave educationlowerthanMS!"); return false; } } else if(jobCategory.equals("Officer") ||jobCategory.equals("officer"))
  • 5. { if(education.equals("Matric") ||education.equals("FSC")) { JOptionPane.showMessageDialog(null,"Officercannothave educationlessthanBS !"); return false; } } else if(jobCategory.equals("Staff") ||jobCategory.equals("staff")) { if(education.equals("Matric")) { JOptionPane.showMessageDialog(null,"Staff cannothave educationlessthanFSc !"); return false; } } else if(jobCategory.equals("Labour") ||jobCategory.equals("labour")) { if(!education.equals("Matric")) { JOptionPane.showMessageDialog(null,"LabourMustbe Matric Pass !"); return false; } }
  • 6. } //if checkingpayscale else if(checkWhat.equals("payscale")) { if(jobCategory.equals("Teacher") ||jobCategory.equals("teacher")) { if(payScale < 18) { JOptionPane.showMessageDialog(null,"TeacherCannothave payscale lowerthan18 !"); return false; } } else if(jobCategory.equals("Officer") ||jobCategory.equals("officer")) { if(payScale < 17) { JOptionPane.showMessageDialog(null,"Officercannothave payscale lessthan 17 !"); return false; } } else if(jobCategory.equals("Staff") ||jobCategory.equals("staff")) { if(payScale < 11 ||payScale > 16) {
  • 7. JOptionPane.showMessageDialog(null,"Staff cannothave payscale lessthan 11 or greater than 16 !"); return false; } } else if(jobCategory.equals("Labour") ||jobCategory.equals("labour")) { if(payScale < 1 || payScale > 10) { JOptionPane.showMessageDialog(null,"LabourMusthave payscale lessthan 11 and greater then0 !"); return false; } } } returntrue;//if correcteducationor payscale } public voidsetEmpInformation() { booleancheckexception= false;
  • 8. do { try { empName = JOptionPane.showInputDialog(null,"EnterEmployee Name :"); empFname = JOptionPane.showInputDialog(null,"EnterEmployee FatherName :"); jobCategory= JOptionPane.showInputDialog(null,"EnterJob Category (teacher,officer,staff,labour) :"); booleancheck; do { education= JOptionPane.showInputDialog(null,"Enter"+jobCategory+"'sEducation (PHD,MS,BS,FSC,Matric) :"); check = checkInformation("education"); }while(!check); do { payScale = Integer.parseInt(JOptionPane.showInputDialog(null,"Enter"+jobCategory+"'s Payscale : ")); check = checkInformation("payscale"); }while(!check); doB = JOptionPane.showInputDialog(null,"EnterEmployee Date of Birth (DD-MM-YYYY) :"); age = Integer.parseInt(doB.substring(6)); age = 2021 - age; NIC= JOptionPane.showInputDialog(null,"EnterEmployee'sNIC:");
  • 9. }catch(Exceptione) { checkexception= true; JOptionPane.showMessageDialog(null,"invalidvalue enteredEnterValuesagain!"); } checkexception= false; }while(checkexception== true); } public voidupdateEmpInformation() { try { jobCategory= JOptionPane.showInputDialog(null,"Enternew JobCategory:"); booleancheck; do { education= JOptionPane.showInputDialog(null,"Enter"+jobCategory+"'snew Education:"); check= checkInformation("education"); }while(!check); do { payScale = Integer.parseInt(JOptionPane.showInputDialog(null,"Enter"+jobCategory+"'snew Payscale : ")); check= checkInformation("payscale");
  • 10. }while(!check); }catch(Exceptione) { JOptionPane.showMessageDialog(null,"EnteraValid Value !"); } } public static int deleteEmpInformation(Employee [] A,intn,intindex) { for(int j = index;j < A.length-1;j++) { A[j] = A[j+1]; } n--; returnn; } public static int search(Employee[] A,intn, int id, String name, int age,String jobcat) { for(int i = 0; i <= n; i++) { if(id!= -1) { if(id == A[i].empId) {
  • 11. return i; } } else if(name != null) { if(name.equals(A[i].empName)) { return i; } } else if(age != -1) { if(A[i].age == age) { return i; } } else if(jobcat!= null) { if (jobcat.equals(A[i].jobCategory)) { return i; } }
  • 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----------------------------