Problem Statement: In this project, you are asked to write a Java application si
ID: 3940848 • Letter: P
Question
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!
Explanation / Answer
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 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; iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.