Java Code. Employee Information System I have created the BasicInfo class and parts of other classes, but I am having trouble completing everything and putting it together. If you could please demonstrate a simple version of this system in java.
Program Description:
This is an Employee Information system, intended for the use of the manager or other administrative personal to store, edit, and re-access their Employees’ information. Simple budget and salary calculations will also be implemented. The following detailed program description contains the minimum program requirements. Students are encouraged to add more features (classes, Methods, etc…) after creating the initial classes and methods.
Implementation Requirements:
This program will include the fundamentals of object-oriented programing and all of the requirements for the final project, including:
Arrays or ArrayLists of objects
Static variables and methods
Method overriding (of the toString())
Composition
Inheritance
Random number generation
The storing, editing, and deleting of data using objects
String methods
Class Descriptions
Class Name: EmployeeClient
Class Description: Create a client class which displays the capabilities of the program. Creativity is encouraged. However, it MUST include the following:
Main should contain a loop, presenting a list of options at the start of each iteration.
Using an array or ArrayList, allow the user to add and delete Employees from the list.
Allow the user to search through the system for specific Employees. If the Employee is found, print their corresponding information.
GUI or console may be used.
Class Name: BasicInfo
Class Description: This class will have instance variables to store each Employee’s:
first name
last name
ID
the specific department they each work for
phone number
address
email address
position title
Include set and get methods for each variable. Include a toString() method which returns a formatted string of an Employee’s data from this class.
Class Name: GenerateID
Class Description: This class will have instance variables for each Employee’s:
Employee ID
position number
department
Variable department should be of type BasicInfo (Composition). Each Employee ID should be a randomly generated 4 digit number. Each position number should be a randomly generated 4 digit number, concatenated to the back of the abbreviation for the department (for example, if the department is Math, the position number should begin with the prefix MA, if English, then ENG, etc).
Include the appropriate methods for each instance variable. Include a toString() method which returns a formatted string notifying the user that a new Employee’s Employee ID and position number have been generated, and display this data.
Class Name: HoursAndSalary
Class Description: this class will allow the administrator to edit:
The salary for the Employees. Note: all Employees receive the same salary.
The budget
The sum of the hours worked each week.
Include code to verify that the salary is above minimum wage, and that the budget and sum of hours are positive number.
Class Name: SalaryCalc
Class Description: this class is a subclass of HoursAndSalary (Inheritance). The variables and methods of this class are largely up to the programmer. However, it is strongly suggested that they be in some way pertaining to salary or budget. This class will:
Calculate the budget deficit or surplus.
Contain at least three instance variables and their corresponding methods.
Expert Answer
EmployeeClient.java
——————————–
import java.util.ArrayList;//importing various library for usage
import java.util.Scanner;
public class EmployeeClient
{ private static int count=0;//instantiating static variable to be used to count how many employees added
public static void main(String[] args)
{
ArrayList<String>employeefName = new ArrayList<>();//arraylist of various private datas to store info
ArrayList<String>employeelName = new ArrayList<>();
ArrayList<String>employeeID = new ArrayList<>();
ArrayList<String>employeeDept = new ArrayList<>();
ArrayList<String>employeePhone = new ArrayList<>();
ArrayList<String>employeeAddress = new ArrayList<>();
ArrayList<String>employeeEmail = new ArrayList<>();
ArrayList<String>employeeTitle = new ArrayList<>();
ArrayList<String>employeeWorkID = new ArrayList<>();
ArrayList<String>employeePositionNum = new ArrayList<>();
Scanner input = new Scanner(System.in);
System.out.println(“Welcome to the Employee Information Managing Programme!nPress y to start!”);//as long as input is y, loop will keep going and asking the user what to do until user wants to quit
String start = input.nextLine();
while (start.equals(“y”))
{
System.out.println(” There are currently “+employeefName.size()+” employees stored in the system.”);//display current number of employees added
System.out.println(” Press a to start adding employee’s info,f to find info about employee,e to edit employee’s info,n d to delete,m for editing financial info and q to quit the program!!”);//presenting options
String whattodo = input.nextLine();
if (whattodo.equals(“a”))
{ //ask users to entere relevant info
System.out.println(“Please enter his/her first name:”);
String fName= input.nextLine();
System.out.println(“Please enter his/her last name:”);
String lName = input.nextLine();
System.out.println(“Please enter his/her ID number:”);
String ID = input.nextLine();
System.out.println(“Please enter his/her department:”);
String department = input.nextLine();
System.out.println(“Please enter his/her phone number:”);
String phone = input.nextLine();
System.out.println(“Please enter his/her address:”);
String address = input.nextLine();
System.out.println(“Please enter his/her email:”);
String email = input.nextLine();
System.out.println(“Please enter his/her title:”);
String title = input.nextLine();
employeefName.add(fName);
employeelName.add(lName);
employeeID.add(ID);
employeeDept.add(department);
employeePhone.add(phone);
employeeAddress.add(address);
employeeEmail.add(email);
employeeTitle.add(title); //add info into appropriate arraylists
BasicInfo employee = new BasicInfo(employeefName.get(count),employeelName.get(count),employeeID.get(count),employeeAddress.get(count),employeeDept.get(count),employeePhone.get(count),employeeEmail.get(count),employeeTitle.get(count));
GenerateID employeeIDno =new GenerateID(employee); //creating new objects to be used by toString
employeeWorkID.add(employeeIDno.getEmployeeID()); //generate random numbers and save into array
employeeIDno.getDepartmentID(department);//grab departmentID to be concatenated to positionnum
employeePositionNum.add(employeeIDno.getPositionNum()); //add info into appropriate arraylists
employeeIDno.getConcatenatedID();//combine departmentID and positionnum…this is done individually and not saved into an array
System.out.printf(“%n%s:%n%n%s%n%n”,”Updated employee info”, employeeIDno.toString());//display using toString
count++;
}
if (whattodo.equals(“f”))
{
System.out.println(“Please enter the employee’s first name:”);//find employee via searching through arraylists
String Name= input.nextLine();
if(employeefName.contains(Name))//if input matches one of the arraylist entries
{
int index=employeefName.indexOf(Name);//display found info using the indexOf function to generate the index number
BasicInfo employee = new BasicInfo(employeefName.get(index),employeelName.get(index),employeeID.get(index),employeeAddress.get(index),employeeDept.get(index),employeePhone.get(index),employeeEmail.get(index),employeeTitle.get(index));
GenerateID employeeIDno =new GenerateID(employee);
employeeIDno.getDepartmentID(employeeDept.get(index));
employeeIDno.setEmployeeID(employeeWorkID.get(index));
employeeIDno.setPositionNum(employeePositionNum.get(index));
employeeIDno.getConcatenatedID();
System.out.printf(“%n%s:%n%n%s%n%n”,”Employee found: “, employeeIDno.toString());
}
else
System.out.println(“Employee cannnot be found in the database!”);
}
if (whattodo.equals(“e”))
{
System.out.println(“Please enter the employee’s first name for identification purpose”);
String Nametobefound = input.nextLine();//using the same mechanism as above to edit info
if(employeefName.contains(Nametobefound))
{
int indexno=employeefName.indexOf(Nametobefound);
int editoption=0;
while (editoption<9) //going into each different arraylist and individually edit the corresponding entry
{ System.out.println(“What categories of info would you like to edit about employee “+employeefName.get(indexno)+ “:”);
System.out.println(“Enter 1 for first name,2 for last name, 3 for ID, 4 for department,n5 for phone number, 6 for address, 7 for email and 8 for position title and 9 or any other number to quit:”);
editoption=input.nextInt();
input.nextLine();
switch(editoption)
{case 1:
System.out.println(“Please enter “+employeefName.get(indexno)+”‘s new first name: “);
String newfirstN=input.nextLine();
employeefName.set(indexno,newfirstN);
break;
case 2:
System.out.println(“Please enter “+employeefName.get(indexno)+”‘s new last name: “);
String newlastN=input.nextLine();
employeelName.set(indexno,newlastN);
break;
case 3:
System.out.println(“Please enter “+employeefName.get(indexno)+”‘s new ID: “);
String newID=input.nextLine();
employeeID.set(indexno,newID);
break;
case 4:
System.out.println(“Please enter “+employeefName.get(indexno)+”‘s new department: “);
String newdept=input.nextLine();
employeeDept.set(indexno,newdept);
break;
case 5:
System.out.println(“Please enter “+employeefName.get(indexno)+”‘s new phone number: “);
String newphone=input.nextLine();
employeeAddress.set(indexno,newphone);
break;
case 6:
System.out.println(“Please enter “+employeefName.get(indexno)+”‘s new address: “);
String newaddress=input.nextLine();
employeeAddress.set(indexno,newaddress);
break;
case 7:
System.out.println(“Please enter “+employeefName.get(indexno)+”‘s new email: “);
String newemail=input.nextLine();
employeeEmail.set(indexno,newemail);
break;
case 8:
System.out.println(“Please enter “+employeefName.get(indexno)+”‘s new position title: “);
String newtitle=input.nextLine();
employeeEmail.set(indexno,newtitle);
break;
default:
System.out.println(“Editing completed!”);
break;
}
BasicInfo employee = new BasicInfo(employeefName.get(indexno),employeelName.get(indexno),employeeID.get(indexno),employeeAddress.get(indexno),employeeDept.get(indexno),employeePhone.get(indexno),employeeEmail.get(indexno),employeeTitle.get(indexno));
GenerateID employeeIDno =new GenerateID(employee);
employeeIDno.getDepartmentID(employeeDept.get(indexno));
employeeIDno.setEmployeeID(employeeWorkID.get(indexno));
employeeIDno.setPositionNum(employeePositionNum.get(indexno));
employeeIDno.getConcatenatedID();//display edited info
System.out.printf(“%n%s:%n%n%s%n%n”,”Employee info has been edited: “, employeeIDno.toString());
}
}
else
{
System.out.println(“Employee cannot be found”);
}
}
if(whattodo.equals(“d”))
{
System.out.println(“Please enter the employee’s first name for identification purpose”);
String Nametobedeleted= input.nextLine();
if(employeefName.contains(Nametobedeleted))//find approriate entry using the same mechanism as above
{
int indexdelete=employeefName.indexOf(Nametobedeleted);
BasicInfo employee = new BasicInfo(employeefName.get(indexdelete),employeelName.get(indexdelete),employeeID.get(indexdelete),employeeAddress.get(indexdelete),employeeDept.get(indexdelete),employeePhone.get(indexdelete),employeeEmail.get(indexdelete),employeeTitle.get(indexdelete));
System.out.printf(“%n%s:%n%n%s%n%n”,”Employee found: “, employee.toString());
System.out.println(“Do you want to remove this employee from the database? Enter y for yes”);
String deleteconfirm=input.nextLine();
if(deleteconfirm.equals(“y”))
{
System.out.println(“Deleting employee “+employeefName.get(indexdelete)+ “‘s info”);
employeefName.remove(indexdelete);
employeelName.remove(indexdelete);
employeeID.remove(indexdelete);
employeeDept.remove(indexdelete);
employeePhone.remove(indexdelete);
employeeAddress.remove(indexdelete);
employeeEmail.remove(indexdelete);
employeeTitle.remove(indexdelete);
employeeWorkID.remove(indexdelete);
employeePositionNum.remove(indexdelete);//remove entry from array list
count–;
}
}
else
System.out.println(“Employee cannot be found”);
}
if ( whattodo.equals(“m”))//ask user to enter appropriate input in order to deduce calculation
{
System.out.println(“Please enter the wage per hours: “);
int salary = input.nextInt();
input.nextLine();
System.out.println(“Please enter the total budget: “);
int budget = input.nextInt();
input.nextLine();
System.out.println(“Please enter the total hours worked per week: “);
int timeworked= input.nextInt();
input.nextLine();
System.out.println(“Please enter the total insurance cost: “);
int insurance = input.nextInt();
input.nextLine();
System.out.println(“Please enter the total bonus to be given out: “);
int bonus = input.nextInt();
input.nextLine();
System.out.println(“Please enter the total overtime hours worked per week: “);
int overtimeworked = input.nextInt();
input.nextLine();
SalaryCalc company = new SalaryCalc(salary,budget,timeworked,insurance,bonus,overtimeworked);
company.totalYearlySalary();
company.miscYearlyCostCalc();
System.out.println(” There are currently “+employeefName.size()+” employees stored in the system.”);
System.out.println(” Is this the correct number of employees?Enter y for yes and n for no!”);
String confirmnumofemployees=input.nextLine();
if (confirmnumofemployees.equals(“y”))
{
company.yearlyExpenseCalc(employeefName.size());//takes in number of employee using the size of the array lists
company.budgetDeficitCalc();
}
else
{
System.out.println(“Please enter the number of employees: “);
int numofemployees = input.nextInt();
input.nextLine();
company.yearlyExpenseCalc(numofemployees);//takes in entered number of employee instead of array lists
company.budgetDeficitCalc();
}
}
if (whattodo.equals(“q”))
{
System.out.println(“The program will now end!”);
break;
}
}
}
}
————————————————————
GenerateID.java
—————————–
import java.util.Random;
public class GenerateID
{
private BasicInfo department;
private String EmployeeID;
private String positionnum;
private String departmentID;
private String concatenatedID;
//instantiating instance variables
public GenerateID(BasicInfo department)
{
this.department=department;//constructor method with composition
}
public void setEmployeeID(String EmployeeID)
{
this.EmployeeID = EmployeeID;//mutator method
}
public void setPositionNum(String positionnum)
{
this.positionnum=positionnum;//mutator method
}
public void setConcatenatedID(String concatenatedID)
{
this.concatenatedID=concatenatedID;
}
public String getEmployeeID()//create random number then return it
{Random randomEmployeeID = new Random(); //creating new random object
{
EmployeeID = Integer.toString(randomEmployeeID.nextInt((9999-1000)+1)+1000); //generate 4 non-unique digits random number
}
return EmployeeID;
}
public String getDepartmentID(String department)//takes in a string and return the short handed version to be used later
{
if (department.equals(“English”))
departmentID = “ENG”;
else if (department.equals(“Sciences”))
departmentID = “SCI”;
else if (department.equals(“Engineering”))
departmentID = “ENGR”;
else if (department.equals(“Math”))
departmentID = “MAT”;
else if (department.equals(“Social Sciences”))
departmentID = “SOC”;
else if (department.equals(“Computer Science”))
departmentID = “CSC”;
else if (department.equals(“Nursing”))
departmentID = “NUR”;
else if (department.equals(“Arts”))
departmentID = “ART”;
else if (department.equals(“Business”))
departmentID = “BUS”;
else
departmentID =”N/A”;
return (departmentID);
}
public String getPositionNum()//create a random number and return the departmentID concatenated at the beginning
{
Random randomPositionNum = new Random();
{
positionnum = Integer.toString(randomPositionNum.nextInt((9999-1000)+1)+1000);
//generating 4 non-unique digits random number
}
return (positionnum);
}
public String getConcatenatedID()
{
concatenatedID = departmentID+positionnum;
return concatenatedID;
}
@Override
public String toString()//display result, including the BasicInfo object
{
return String.format(“%snEmployeeID: %snPosition Number: %sn”,department,EmployeeID,concatenatedID);
}
}
—————————————————————————
BasicInfo.java
——————————–
public class BasicInfo
{
private String firstName,lastName,ID,department,phone,address,email,title;//íntantiating instance variable to stor datas
public BasicInfo(String firstName,String lastName, String ID,String address, String department, String phone, String email,String title)
{
this.firstName= firstName;
this.lastName=lastName;
this.ID=ID;
this.department=department;
this.phone=phone;
this.address=address;
this.email=email;
this.title=title;
//constructor method
}
public void setFirstName(String firstName)//
{
this.firstName = firstName;
//mutator method
}
public void setLastName(String lastName)
{
this.lastName =lastName;
//mutator method
}
public void setID(String ID)
{
this.ID=ID;
//mutator method
}
public void setDepartment(String department)
{
this.department= department;
//mutator method
}
public void setAddress(String address)
{
this.address=address;
//mutator method
}
public void setEmail(String email)
{
this.email=email;
//mutator method
}
public void setTitle(String title)
{
this.title=title;
//mutator method
}
public void setPhone(String phone)
{
this.phone=phone;
//mutator method
}
public String getfirstName()
{
return firstName;
//assessor method
}
public String getlastName()
{
return lastName;
//assessor method
}
public String getID()
{
return ID;
//assessor method
}
public String getDepartment()
{
return department;
//assessor method
}
public String getPhone()
{
return phone;
//assessor method
}
public String getAddress()
{
return address;
//assessor method
}
public String getEmail()
{
return email;
//assessor method
}
public String getTitle()
{
return title;
//assessor method
}
@Override
public String toString()
{
return String.format(“First Name: %s Last Name: %snID: %snDepartment: %snPhone Number: %snAddress: %snEmail Address: %snTitle: %s”, getfirstName(), getlastName(),getID(),getDepartment(),getPhone(),getAddress(),getEmail(),getTitle());
//overriden toString method to display all the entered variables.
}
}
—————————————————————–
SalaryCalc.java
——————————–
public class SalaryCalc extends HoursAndSalary
{//several different simple calculations to be done to try and find various financial aspects
private int insurance;
private int overtimepayperhour;
private int overtimeworked;//based on 1 week
private double bonus;
private double miscCost;
private double yearlyExpense;
private double totalsalary;
public SalaryCalc(int payperhours,int budget,int totalhoursperweek,int insurance,double bonus, int overtimeworked )
{
super(payperhours,budget,totalhoursperweek);
if (insurance < 0)
{System.out.println(“Numbers have to be non-negative. It has to been set to zero”);
insurance =0;
}
if (overtimeworked < 0)
{
System.out.println(“Numbers have to be non-negative.It has to been set to zero.”);
overtimeworked =0;
}
if (bonus < 0)
{
System.out.println(“Numbers have to be non-negative.It has to been set to zero.”);
bonus =0;
}
overtimepayperhour=payperhours*(1/3)+payperhours;//overtime work modifier
this.insurance=insurance;
this.bonus= bonus;
this.overtimeworked = overtimeworked;
}
public void setInsurance(int insurance)
{
if (insurance < 0)
{System.out.println(“Numbers have to be non-negative. It has to been set to zero”);
insurance =0;
}
this.insurance=insurance;
}
public void setOvertimePay( int overtimepayperhour)
{
if (overtimepayperhour < 9)
{
System.out.println(“Numbers have to be non-negative.It has to been set to zero.”);
overtimeworked =0;
}
this.overtimepayperhour= overtimepayperhour;
}
public void setBonus ( int bonus)
{
if (bonus < 0)
{
System.out.println(“Numbers have to be non-negative.It has to been set to zero.”);
bonus =0;
}
this.bonus=bonus;
}
public void setOvertimeWorked( int overtimeworked)
{
if (overtimeworked < 0)
{
System.out.println(“Numbers have to be non-negative.It has to been set to zero.”);
bonus =0;
}
this.overtimeworked=overtimeworked;
}
public int getInsurance()
{
return insurance;
}
public int getOvertimePay ()
{
return overtimepayperhour;
}
public double getBonus()
{
return bonus;
}
public double getOvertimeWorked()
{
return overtimeworked;
}
public double totalYearlySalary()
{
totalsalary = (totalhoursperweek*payperhours*52)+(overtimepayperhour*overtimeworked*52); //52 weeks in a year
System.out.println(“The total amount of salary paid out to employee including overtime is $”+totalsalary);
return totalsalary;
}
public double miscYearlyCostCalc()
{
miscCost=bonus+insurance;
System.out.println(“The miscelanous cost has an amount of $”+miscCost);
return miscCost;
}
public double yearlyExpenseCalc ( int noofemployee)
{
yearlyExpense=totalsalary*noofemployee+miscCost;
System.out.println(“The yearly expense has an amount of $”+yearlyExpense+”which consisted of misc. cost and total salary paid to “);
return yearlyExpense;
}
public void budgetDeficitCalc ()
{
double Deficit= budget-yearlyExpense;
if (Deficit> 0.0)
System.out.println(“The current budget has a surplus of $”+Deficit);
else
System.out.println(“The current budget has a deficit of $”+Deficit);
}
}
————————————————————————————–
HoursAndSalary.java
——————————–
public class HoursAndSalary
{
protected static double payperhours ;//static variables to be used for every employees
protected static int budget ;
protected static int totalhoursperweek ;//total time based on a week
public HoursAndSalary(int payperhours,int budget,int totalhoursperweek)//there are several calculations to be done.This class checks for errors and set variables to zero.
{
if (payperhours < 9)
{
payperhours = 0;
System.out.println(“Wage per hour has to meet minimum wage level of $9.00. The salary has been set to zero”);
}
if (budget < 0)
{
budget =0;
System.out.println(“Budget has to be positive.It has been set to zero.”);
}
if (totalhoursperweek < 0)
{
payperhours = 0;
System.out.println(“Total time worked has to be positive. It has been set to zero.”);
}
this.payperhours=payperhours;
this.budget=budget;
this.totalhoursperweek=totalhoursperweek;
}
public void setSalary(int payperhours)
{
if (payperhours < 9.0)
{
payperhours = 0;
System.out.println(“Wage per hour has to meet minimum wage level of $9.00. The salary has been set to zero”);
}
this.payperhours=payperhours;
}
public void setBudget(int budget)
{
if (budget < 0)
{
budget =0;
System.out.println(“Budget has to be positive.It has been set to zero”);
}
this.budget=budget;
}
public void setTimeWorked(int totalhoursperweek)
{
if (totalhoursperweek< 0)
{
payperhours = 0;
System.out.println(“Total time worked has to be positive. It has been set to zero.”);
}
this.totalhoursperweek=totalhoursperweek;
}
public double getSalary()
{
return payperhours;
}
public int getBudget()
{
return budget;
}
public int getTimeWorked()
{
return totalhoursperweek;
}
}