Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Anyone with PayPal want to put this together for $15? Employee Management Progra

ID: 653580 • Letter: A

Question

Anyone with PayPal want to put this together for $15?

Employee Management Program

1) Write a code to implement the structure data type Employee. Employee has three members: int employeeId, string employeeName and string departmentName.

2) Implement a function saveEmployee that accepts fstream fileStream and Employee emp as arguments. The function will use fileStream to write emp. The data will be written by using theappend mode and the following format: employeeId;employeeName;departmentName.

3) Implement a function getEmployeeList that has the arguments: fstream fileStream and int n. The function will return an array employeeArray of length n. The function will read n employees from the file and save them in employeeArray. (you will use the string functions to parse each line)

4) In the main function, you ask the user to enter the number of Employee records that he wants to save and the file name that he wants to use. You will use the file name to create an fstream object. After finishing the writing operation, you will use the same stream object to read all the saved records and display them on the console. The fstream object will be closed after finishing the reading and writing operations.

Explanation / Answer

import java.util.*;
import payslips.Employee;
import payslips.Payslip;

public class MainProgramme
{
public static String name;
public static String street;
public static String town;
public static String postcode;
public static int payrollNo;
public static char taxcode;
public static String type;

static Scanner sc = new Scanner(System.in);
static Scanner sd = new Scanner(System.in);
static int tempvar;
static int temppayrollNo;

static ArrayList<Employee> list = new ArrayList<Employee>();

static String names[] = { "John Hepburn", "David Jones", "Louise White",
"Harry Martin", "Christine Robertson" };

static String streets[] = { "50 Granton Road", "121 Lochend Park",
"100 Govan Avenue", "51 Gorgie Road", "1 Leith Street" };

static String towns[] = { "Edinburgh", "Edinburgh", "Glasgow", "Edinburgh",
"Edinburgh" };

static String postcodes[] = { "EH6 7UT", "EH1 1BA", "G15 5GG", "EH5 2PR",
"EH4 4ST" };

static int payrollNos[] = { 10001, 10002, 10003, 10004, 10005 };

static char taxcodes[] = { 'C', 'B', 'C', 'C', 'B' };

static String types[] = { "Monthly", "Weekly", "Monthly", "Monthly","Weekly" };

public static void main(String[] args)
{
for (int i = 0; i < 5; i++) {
name = names[i];
street = streets[i];
town = towns[i];
postcode = postcodes[i];
payrollNo = payrollNos[i];
taxcode = taxcodes[i];
type = types[i];
Employee e = new Employee(name, street, town, postcode, payrollNo,taxcode, type);

list.add(e);

}

System.out.println("Welcome to your Payroll System");
System.out.println();
System.out.println("Please enter your choice below from the following options");
System.out.println();
System.out.println("View all current weekly employees = 1 ");
System.out.println("View all current monthly employees = 2 ");
System.out.println("Delete an employee = 3 ");
System.out.println("Add an employee = 4 ");
System.out.println("Print an employee payslip = 5");
System.out.println("To exit the system = 0 ");
tempvar = sc.nextInt();
userChoice();
}

// method to determine what statement runs according to which choice user makes
public static void userChoice()
{
Employee tempEmployee = new Employee();
boolean foundEmployee = false;
if (tempvar == 1)
{
Weekly.printWeekly();

}
else if (tempvar == 2)
{
Monthly.printMonthly();

}
else if (tempvar == 3)
{
printEmployeelist();
System.out.println("");
System.out.println("Above are a list of all employees.");
System.out.println("Please enter the payroll number of the employee you wish to delete from the system");
temppayrollNo = sc.nextInt();

// while loop to search on payroll number, deletes the employee if correct, error message if not
if (list.isEmpty() == false)
{
int a = 0;
while (a < list.size())
{
tempEmployee = list.get(a);
if (tempEmployee.payrollNo == temppayrollNo)
{
foundEmployee = true;
break;
}
a++;
}
if (foundEmployee == true)
{
System.out.println("You have deleted : "+ tempEmployee.getName());
System.out.println();
list.remove(tempEmployee);
printEmployeelist();
}
else
{
System.out.println("The payroll number you have entered is incorrect");
}
}
}

else if (tempvar == 4) // allows the user to add an employee to the employee list, entering details using scanner
{
// initialises variables for entering title
String tempstring1;
int stringlength;
int whitespace;
String tempstring2;
String tempstring3;
// initialises variables for entering title
String tempstring4;
int stringlength2;
int whitespace2;
String tempstring5;
String tempstring6;

   String tempstring7;

System.out.println("You have chosen to add an employee to the system");
System.out.println();
System.out.println("Please enter the name of the new employee: ");
tempstring1 = sd.nextLine(); // takes in string using scanner
stringlength = tempstring1.length(); // saves length of string
if (tempstring1.contains(" ")) // if statement to see if the string contains a space
{
whitespace = tempstring1.indexOf(" ");
tempstring2 = tempstring1.substring((0), (whitespace));
tempstring3 = tempstring1.substring((whitespace) + 1,(stringlength));
tempEmployee.setName(tempstring2 + " " + tempstring3);
}
else
{
tempEmployee.setName(tempstring1);
}

System.out.println("Please enter the address of the employee: ");
tempstring4 = sd.nextLine();
stringlength2 = tempstring4.length();
if (tempstring4.contains(" ")) {
whitespace2 = tempstring4.indexOf(" ");
tempstring5 = tempstring4.substring((0), (whitespace2));
tempstring6 = tempstring4.substring((whitespace2) + 1,(stringlength2));
tempEmployee.setStreet(tempstring5 + " " + tempstring6);
}
else
{
tempEmployee.setStreet(tempstring4);
}

System.out.println("Please enter the town: ");
tempEmployee.setTown(sd.nextLine());// takes in town using scanner
System.out.println("Please enter the postcode: ");
tempstring7 = sd.nextLine(); //post code using scanner

if (tempstring7.length() > 5 && tempstring7.length() < 9)

{
tempEmployee.setPostcode(tempstring7);
}
else
{
tempEmployee.setPostcode("You have not entered a valid UK postcode");
}

tempEmployee.setPayrollNo(payrollNo + 1);

System.out.println("Please enter your Tax code (A, B or C): ");
tempEmployee.setTaxcode(sd.next().charAt(0));

System.out.println("Please enter Employee Type (Weekly or Monthly): ");
tempEmployee.setType(sd.next());

list.add(tempEmployee);
printEmployeelist();

else if (tempvar == 5)
{
Payslip.Payslips();
}

else if (tempvar == 0)

{
System.out.println("You have exited the system");
System.exit(0);
}

else
{
System.out.println("You have entered the wrong choice");
}
}
public static void printEmployeelist() {
for (int i = 0; i < list.size(); i++)
System.out.println(list.get(i));
}
}
package payslips;// salary

import java.util.Scanner;

public class Payslip extends MainProgramme

{
static int tempSalary;
static double tempHours;
static Scanner ss = new Scanner(System.in);

public static void Payslips()
{

{
Employee tempEmployee = new Employee();
boolean foundEmployee = false;

{
System.out.println("Please enter the employee payroll number to view payslip");
temppayrollNo = sc.nextInt();

if (list.isEmpty() == false)
{
int a = 0;
while (a < list.size())
{
tempEmployee = list.get(a);
if (tempEmployee.payrollNo == temppayrollNo)
{
foundEmployee = true;
break;
}
a++;
}
if (foundEmployee == true)
{

tempEmployee.getType();
if (tempEmployee.type == "Weekly")
{
System.out.println("Please enter hours worked this week: ");
tempHours = ss.nextDouble();
System.out.println();
System.out.println("PAYSLIP");
System.out.println("Week No:"+ (int) (Math.random() * 52));
System.out.println("Name: "+ tempEmployee.getName());
System.out.println("Payroll No: "+ tempEmployee.getPayrollNo());
System.out.println("Address: "+ tempEmployee.getStreet() + ", "+ tempEmployee.getTown() + ", "+ tempEmployee.getPostcode());
System.out.println("Tax Code: "+ tempEmployee.getTaxcode());
System.out.println("Weekly Pay:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote