Problem Statement In this project you are asked to write a J

Problem Statement:

In this project, you are asked to write a Java application similar to the one you wrote in Project 2 that handles a list of employees employed by a certain company. Your code in project 2 had used the built-in functionalities of the LinkedList class defined in the Java Collection Classes. In this project, you will still use a LinkedList as the main data structure that stores your data but you will provide your own implementation of a class called RecLinkedLink. In doing so, all the required methods to be defined in your RecLinkedList needs to be implemented using recursive algorithms. In other words, method such as size(), replace(), add(), remove, etc. MUST use recursion to achieve it functions. (check chapter 5 for details).

As done before, we will assume that each employee is only represented by her/his first name. The names of all employees in this small company are stored in a given data file called empNames.txt which is posted on Moodle next to this project statement. Your program must do the following task:

1. Define your own recursive implementation of LinkList in a separate file called “RecLinkedList.java”.

2. Create an object of RecLinkedList to be used in storing and handling employees’ data.

3. Open the given file and read employee data into the RecLinkedList object. In doing so, your code needs to maintain the order of employee data in the input file.

4. Verify the content of the employee data (just read) by displaying them on the monitor using a traditional for loop along with appropriate output messages.

5. Invoke various methods of the RecLinkedList class to retrieve then display the first element and the last element of the list. Display appropriate messages on the monitor.

6. Invoke various methods of the RecLinkedList class to remove the last element then display the size of the list after the removal operation. Display appropriate messages on the monitor.

7. Display the current list contents using the enhanced for loop along with appropriate output messages.

8. Create a ListIterator object, iter, to be used in accessing the RecLinkedList contents.

9. Advance the iterator for five positions then display the current list item (using iterator method and NOT list method).

10. Insert a new employee called “Kelly” at the current iterator position then display the current list contents using the compact form to be used from this point on for any list content display. Hint, use the implicit toString().

11. Execute the iter.previous() method followed by using the iter.set() method to set the current element to Nancy. Then, display the current list contents.

12. Execute the iter.previous() method followed by the remove() method then display the current list contents.

13. In a separate file, create a helper class called HelpLists. This class need to have the code for two methods described below:

a. public void reverse(RecLinkedList strings). This method receives a RecLinkedList object as its parameter then linearly access all the elements in the object while pushing them in a STACK object. You need to use the STACK data structure that you just created to retrieve the data from the stack and display them in reserve order on the monitor.

b. public void FIFO(RecLinkedList strings). This method receives a RecLinkedList object as its parameter then linearly access all the elements in the object while inserting them in a QUEUE object. You need to use the QUEUE data structure that you just created to retrieve the data from the queue and display them in order on the monitor.

14. In your main class, create an object of type HelpLists class then use it in the following.

15. Invoke the reverse method to reverse the order then display the reversed list contents.

16. Invoke the FIFO() method in order to create a queue and use it to ensure that the order of the data in RecLinkedList will be displayed without change.

EmpNames.txt file

please do in detail, as followed in instructions. thanks!

Solution

package payslips; 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 list = new ArrayList(); 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); } // statements and prompts within the console for the user to follow 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 \"); // allows user to enter number of choice and this reflects which statement is ran in userChoice method tempvar = sc.nextInt(); // runs the userChoice method 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 user enters 1 it prints out the employee list. 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(); // block of code that builds string together to get employee name 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(\" \"); // finds the whitespace tempstring2 = tempstring1.substring((0), (whitespace));// creates string from start of input to whitespace tempstring3 = tempstring1.substring((whitespace) + 1,(stringlength));// creates string from whitespace plus one and adds on rest of the string tempEmployee.setName(tempstring2 + \" \" + tempstring3); // combines tempstring1 and tempstring2 together to complete full string } else // else statement that just enters the string if it is just one word { tempEmployee.setName(tempstring1); } // block of code that repeats same process as above to get street name 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) // sets the length of string { tempEmployee.setPostcode(tempstring7); } else { tempEmployee.setPostcode(\"You have not entered a valid UK postcode\"); } tempEmployee.setPayrollNo(payrollNo + 1); // sets payroll number to next in sequence System.out.println(\"Please enter your Tax code (A, B or C): \"); tempEmployee.setTaxcode(sd.next().charAt(0));// takes in tax code using scanner System.out.println(\"Please enter Employee Type (Weekly or Monthly): \"); tempEmployee.setType(sd.next()); //takes in type of employee list.add(tempEmployee);// creates temp employee and adds to list printEmployeelist();// prints employee list to view } else if (tempvar == 5) { Payslip.Payslips(); //runs payslip method from payslip class } else if (tempvar == 0) // if user hits 0 it allows them to exit the programme { System.out.println(\"You have exited the system\"); System.exit(0); } else // if any other choice entered they will be met with this message { System.out.println(\"You have entered the wrong choice\"); } } // method to create the book list using a for loop public static void printEmployeelist() { for (int i = 0; i < list.size(); i++) System.out.println(list.get(i)); } } package payslips; 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: £\"+ (tempHours * 8.50)); } else { System.out.println(\"Please Enter Salary (£): \"); tempSalary = ss.nextInt(); System.out.println(); System.out.println(\"PAYSLIP\"); System.out.println(\"Month No:\"+ (int) (Math.random() * 12)); 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(\"Salary : £\" + tempSalary + \" Monthly Pay: £\"+ (tempSalary / 12)); } } else { System.out.println(\"The payroll number you have entered is incorrect\"); } } } } } } package payslips; import payslips.MainProgramme; public class Employee extends MainProgramme { public Employee() { } //initialises variables public String name; public String street; public String town; public String postcode; public int payrollNo; public char taxcode; public String type; public Employee(String name, String street, String town, String postcode, int payrollNo, char taxcode, String type) { //sets constructors this.name = name; this.street = street; this.town = town; this.postcode = postcode; this.payrollNo = payrollNo; this.taxcode = taxcode; this.type = type; } //sets the getters and setters public String getName() { return name; } public void setName(String name) { this.name = name; } public String getStreet() { return street; } public void setStreet(String street) { this.street = street; } public String getTown() { return town; } public void setTown(String town) { this.town = town; } public String getPostcode() { return postcode; } public void setPostcode(String postcode) { this.postcode = postcode; } public int getPayrollNo() { return payrollNo; } public void setPayrollNo(int payrollNo) { this.payrollNo = payrollNo; } public char getTaxcode() { return taxcode; } public void setTaxcode(char taxcode) { this.taxcode = taxcode; } public String getType() { return type; } public void setType(String type) { this.type = type; } //when printing employee list method it sets the input to display as below public String toString() { return \"Name: \" + this.name + \" / \" + \"Street: \" + this.street + \" / \" + \"Town: \" + this.town + \" / \" + \"Postcode: \" + this.postcode + \" / \" + \"Payroll Number: \" + this.payrollNo + \" / \" + \"Tax Code: \" + this.taxcode + \" / \" + \"Type: \" + this.type; } } package payslips; public class Monthly extends MainProgramme { public static void printMonthly() { for (int i = 0; i < list.size(); i++) if (types[i] == \"Monthly\") { System.out.println(list.get(i)); } } } package payslips; public class Weekly extends MainProgramme { public static void printWeekly() { for (int i = 0; i < list.size(); i++) if (types[i] == \"Weekly\") { System.out.println(list.get(i)); } } }
Problem Statement: In this project, you are asked to write a Java application similar to the one you wrote in Project 2 that handles a list of employees employe
Problem Statement: In this project, you are asked to write a Java application similar to the one you wrote in Project 2 that handles a list of employees employe
Problem Statement: In this project, you are asked to write a Java application similar to the one you wrote in Project 2 that handles a list of employees employe

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site