Question: Part I: Create a doubly linked circular list class named LinkedItemList that implements the following interface: /** * An ordered list of items. */ public

Part I:

Create a doubly linked circular list class named LinkedItemList that implements the following interface:

/**

* An ordered list of items.

*/

public interface ItemList {

/**

* Append an item to the end of the list

*

* @param item item to be appended

*/

public void append(E item);

/**

* Insert an item at a specified index position

*

* @param item item to be inserted

* @param index index position where to insert the item

* @throw IndexOutOfBoundsException if index is < 0 or > no of items

*/

public void insert(E item, int index);

/**

* Return an item at a specified index

*

* @param index index of the item to return

* @return the item at the specified index

* @throw IndexOutOfBoundsException if index is < 0 or >= no of items

*/

public E get(int index);

/**

* Remove an item at a specified index

*

* @param index index of the item to be removed

* @return the removed item

* @throw IndexOutOfBoundsException if index is < 0 or >= no of items

*/

public E removeAtIndex (int index);

/**

* Return the number of items currently in the list

*

* @return the number of items in the list

*/

public int size();

/**

* Determine if the list is empty

*

* @return true if the list is empty, otherwise false

*/

public boolean isEmpty();

/**

* Clear the list. The list becomes empty

*

*/

public void clear();

}

You will need the appropriate constructors. In addition, you may also implement other methods that may be useful for the assignment (where possible define code in just one place).

Part II:

Write JUnit test program to thoroughly test all of the methods of your LinkedItemList class. Once you are confident is it working correctly, proceed to part III.

Part III:

You will find an eclipse project called Asmt3. On importing this project you will find a program CompanyReport which is similar to the Company and Bank projects. That is they use arrays for 1 to N relationships between business objects. Make the following modifications to CompanyReport to use ItemList and LinkedItemList.

1)Change the Company class to use LinkedItemList for your list of departments (instead of using an array). Define the type of the departments variable to be an ItemList. You will need to modify for loop accordingly.

2)Change Department to use LinkedItemList for the list of employees (instead of an array). Define the employees variable as an ItemList of Employees.

Additional Requirements:

The LinkedItemList must be implemented as a doubly linked circular list with a dummy node in place of a first node and last node reference variables.

Place ItemList and LinkedItemList into package edu.www.xxxx310.util

Provide a fast implementation for append(), e.g., does not need to walk the list to get to the end.

Define and use a private method appendAfter(Node node, E item) which adds a Node to the linked list for the item. Call appendAfter from the append and insert methods. The append and insert methods must not directly create a node.

Define and use a private method removeNode(Node node) which removes a Node from the linked list. Call removeNode from the removeAtIndex method. The removeAtIndex method must not directly remove a node.

Define and use a private method getNode(int index) which returns a node at a given index position. Use getNode in the get, removeAtIndex, and insert methods

Provide a fast implementation for size(), e.g., does not need to walk the list to count the number of items.

Employee.java:

package edu.www.xxxx310.company.bo;

import java.time.LocalDate;

import java.util.Date;

/**

* An Employee of a Company.

*

* @author

*/

public class Employee {

private String firstName;

private String lastName;

private String employeeId;

private String employeeIndicator;

private String deptCode;

private float salary;

private LocalDate hireDate;

private short vacationDays;

private byte training;

/**

* Constructor for Employee

* @param firstName - first name of the employee

* @param lastName - last name of the employee

* @param employeeId - the employee's id number

* @param employeeIndicator - indicates if an employee ("E") or a contractor ("C")

* @param deptCode - department code of the employee's department

* @param salary - the employee's salary

* @param hireDate - the date the employee was hired

* @param vacationDays - the number of vacation days

* @param training - a byte using bits to indicated the training the employee has received

*/

public Employee(String employeeId, String employeeIndicator, String deptCode, String firstName, String lastName, float salary, LocalDate hireDate, short vacationDays, byte training){

this.employeeId = employeeId;

this.employeeIndicator = employeeIndicator;

this.deptCode = deptCode;

this.firstName = firstName;

this.lastName = lastName;

this.salary = salary;

this.hireDate = hireDate;

this.vacationDays = vacationDays;

this.training = training;

}

/**

* Get the employee's id

* @return - the employee's id

*/

public String getEmployeeId() {

return employeeId;

}

/**

* Get the employee's indicator code E for employee, C for contractor

* @return - the employee's indicator code

*/

public String getEmployeeIndicator() {

return employeeIndicator;

}

/**

* Get the employee's department code.

* @return - the employee's department code

*/

public String getDeptCode() {

return deptCode;

}

/**

* Get the employee's first name

* @return - the employee's first name

*/

public String getFirstName() {

return firstName;

}

/**

* Get the employee's last name

* @return - the employee's last name

*/

public String getLastName() {

return lastName;

}

/**

* Get the employee's full name (i.e., first name and last name)

* @return - the employee's full name

*/

public String getFullName() {

return firstName + " " + lastName;

}

/**

* Get the employee's salary

* @return - the employee's salary

*/

public float getSalary() {

return salary;

}

/**

* Get the employee's hire date as a string of the form mm/dd/yyyy.

* @return - returns the employee's hire date

*/

public LocalDate getHireDate() {

return hireDate;

}

/**

* Get the number of vacation days for an employee

* @return - the number of vacation days an employee has

*/

public short getVacationDays() {

return vacationDays;

}

/**

* Get the encoded traning byte.

* @return - a byte whose bits indicate traingin the employee has recieved

*/

public byte getTraining() {

return training;

}

}

Department.java:

package edu.www.xxxx310.company.bo;

/**

* A Department of a Company.

*

* @author

*

*/

public class Department {

private String deptCode;

private String deptName;

private String mgrEmpId;

private Employee[] employees = new Employee[100];

private int noEmployees;

private Employee manager;

/**

* Constructor for Department.

*

* @param deptCode

* - the department code

* @param deptName

* - the department name

* @param mgrEmpId

* - the manager's employee id for the department

*/

public Department(String deptCode, String deptName, String mgrEmpId) {

this.deptCode = deptCode;

this.deptName = deptName;

this.mgrEmpId = mgrEmpId;

}

/**

* Add an employee to the department's list of employees

*

* @param employee

* - employee to add to the department

*/

public void addEmployee(Employee employee) {

employees[noEmployees++] = employee;

}

/**

* Get the code for the department

*

* @return - the code for the department

*/

public String getDeptCode() {

return deptCode;

}

/**

* Get the name of the department

*

* @return - the name of the department

*/

public String getDeptName() {

return deptName;

}

/**

* Get the manager of the department. The manager is indicated by the

* mgrEmpId passed on the constructor. The manager must be an employee of

* the department, otherwise null is returned.

*

* @return - the department manager.

*/

public Employee getManager() {

if (manager == null) {

for (int i = 0; i < noEmployees; i++) {

Employee emp = employees[i];

if (emp.getEmployeeId().equals(mgrEmpId)) {

manager = emp;

break;

}

}

}

return manager;

}

/**

* Get the number of employees in the department

*

* @return - the number of employees in the department

*/

public int getNoEmployees() {

return noEmployees;

}

/**

* Get an employee given an index position

*

* @param emp

* - the employee to return

* @return - the employee at the given position

* @throws IndexOutOfBoundsException

* if the index is less that 0 or greater than or equal to the

* number of employees.

*/

public Employee getEmployee(int index) {

return employees[index];

}

/**

* Get total number of vacation days of all employees in the department

*

* @return - the total number of vacation days

*/

public int getTotalVacationDays() {

int totalVacationDays = 0;

for (int i = 0; i < noEmployees; i++) {

Employee emp = employees[i];

totalVacationDays += emp.getVacationDays();

}

return totalVacationDays;

}

}

Company.java:

package edu.www.xxxx310.company.bo;

/**

* A Company. Maintains a list of departments and methods access

* the company's departments.

*

* @author

*/

public class Company {

private Department[] departments = new Department[10];

private int noDepartments = 0;

/**

* Add a Department to the list of departments for this company.

*

* @param department - the company to be added

*/

public void addDepartment(Department department) {

departments[noDepartments++] = department;

}

/**

* Find a department with a given department code

*

* @param deptCode - the department code used to find a department

* @return the department with the given code. Returns null if

* a department by the given department code is not found.

*/

public Department findDepartment(String deptCode) {

for (int i = 0; i < noDepartments; i++) {

Department department = departments[i];

if (deptCode.equals(department.getDeptCode())) {

return department;

}

}

return null;

}

/**

* Get the number of departments in this company.

* @return the number of departments in this company.

*/

public int getNoDepartments() {

return noDepartments;

}

/**

* Get the ith department in this company

* @param i - index identifying the department to be returned

* @return the ith department in this company

*/

public Department getDeparment(int i) {

return departments[i];

}

}

ReadEmployeeFile.java:

package edu.www.xxxx310.company.io;

import java.io.DataInputStream;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.IOException;

import java.time.LocalDate;

import java.util.Date;

import edu.iup.cosc310.company.bo.Employee;

/**

* Helper class to read employees from a binary employee file.

* The method readEmployee() returns the next employee from

* the employee file.

*

* @author

*/

public class ReadEmployeeFile {

private DataInputStream input;

/**

* Constructor - opens the employee file.

* @param fileName - name of the employee file

* @throws FileNotFoundException - in the event the file could not be opened

*/

public ReadEmployeeFile(String fileName) throws FileNotFoundException {

input = new DataInputStream(new FileInputStream(fileName));

}

/**

* Read the next employee from the employee file.

* @return an employee. Returns null in the event the end of

* the employee file is reached.

* @throws IOException

*/

@SuppressWarnings("deprecation")

public Employee readEmployee() throws IOException {

// Test for end of file

if (input.available() == 0) {

return null;

}

// declare byte buffers for the ascii fields.

byte[] employeeIdByte = new byte[3];

byte[] lastNameBytes = new byte[15];

byte[] firstNameBytes = new byte[20];

input.read(employeeIdByte);

String employeeId = new String(employeeIdByte);

String empIndicator = "" + (char) input.readByte();

String deptCode = "" + (char) input.readByte();

input.read(lastNameBytes);

String lastName = new String(lastNameBytes).trim();

input.read(firstNameBytes);

String firstName = new String(firstNameBytes).trim();

float salary = input.readFloat();

byte month = input.readByte();

byte day = input.readByte();

short year = input.readShort();

LocalDate hireDate = LocalDate.of(year, month, day);

short vacationDays = input.readShort();

byte training = input.readByte();

Employee employee = new Employee(employeeId, empIndicator, deptCode, firstName,

lastName, salary, hireDate, vacationDays, training);

return employee;

}

/**

* Close the employee file

* @throws IOException

*/

public void close() throws IOException {

input.close();

}

}

ReadDepartmentFile.java:

package edu.www.xxxx310.company.io;

import java.io.BufferedReader;

import java.io.FileNotFoundException;

import java.io.FileReader;

import java.io.IOException;

import edu.iup.cosc310.company.bo.Department;

/**

* Helper class to read departments from a comma separated

* department text file. The method readDepartment() returns

* the next department from the department file.

*

* @author

*/

public class ReadDepartmentFile {

BufferedReader input;

/**

* Constructor - opens the department file.

* @param fileName - name of the department file

* @throws FileNotFoundException - in the event the file could not be opened

*/

public ReadDepartmentFile(String fileName) throws FileNotFoundException {

input = new BufferedReader(new FileReader(fileName));

}

/**

* Read the next department from the department file.

* @return a department. Returns null in the event the end of

* the department file is reached.

* @throws IOException

*/

public Department readDepartment() throws IOException {

String line = input.readLine();

// Test for end of file

if (line == null) {

return null;

}

String[] parts = line.split(",");

String deptCode = parts[0];

String deptName = parts[1];

String mgrEmpId = parts[2];

return new Department(deptCode, deptName, mgrEmpId);

}

/**

* Close the department file

* @throws IOException

*/

public void close() throws IOException {

input.close();

}

}

CompanyReport.java:

package edu.www.xxxx310.company.rpt;

import java.io.FileNotFoundException;

import java.io.IOException;

import java.text.SimpleDateFormat;

import java.time.format.DateTimeFormatter;

import edu.iup.cosc310.company.bo.Company;

import edu.iup.cosc310.company.bo.Department;

import edu.iup.cosc310.company.bo.Employee;

import edu.iup.cosc310.company.io.ReadDepartmentFile;

import edu.iup.cosc310.company.io.ReadEmployeeFile;

/**

* Print the company report for a Company.

*

* @author

*/

public class CompanyReport {

private Company company = new Company();

private static DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");

/**

* Main method to print the company report: Creates a company, loads

* Departments from the file name given in the first command line argument, and

* loads Employees from the file name given in the last command line

* argument

*

* @param args - the command line arguments.

*/

public static void main(String[] args) {

if (args.length < 2) {

System.out

.println("Usage: java edu.iup.cosc310.company.rpt.CompanyReport ");

System.exit(-99);

}

CompanyReport companyReport = new CompanyReport();

try {

companyReport.loadDepts(args[0]);

companyReport.loadEmployees(args[1]);

companyReport.printCompanyReport();

} catch (FileNotFoundException e) {

System.out.println("Unable to run: " + e.getMessage());

System.exit(-1);

} catch (IOException e) {

e.printStackTrace();

} catch (Exception e) {

e.printStackTrace();

}

}

/**

* Load departments from a text file.

* @param fileName - the filename of the file that contains the departments.

* @throws IOException - in the event the file cannot be opened or read.

*/

public void loadDepts(String fileName) throws NumberFormatException,

IOException {

ReadDepartmentFile in = new ReadDepartmentFile(fileName);

Department department;

while ((department = in.readDepartment()) != null) {

company.addDepartment(department);

}

}

/**

* Load Employees from a binary file. The employees are added to the list of employees

* for their respective Department as indicated by deptCode.

* @param fileName - the name of the file that contains the employees.

* @throws Exception - catches an Exception.

*/

public void loadEmployees(String fileName) throws Exception {

ReadEmployeeFile in = new ReadEmployeeFile(fileName);

Employee employee;

while ((employee = in.readEmployee()) != null) {

Department dept = company.findDepartment(employee.getDeptCode());

dept.addEmployee(employee);

}

}

/**

* Prints a company report. Report include information on the department

* and a list of all employees.

*/

public void printCompanyReport() {

// loop over all departments

for (int i = 0; i < company.getNoDepartments(); i++) {

Department department = company.getDeparment(i);

// print the department header

System.out.println(department.getDeptName() + " Department");

System.out.println();

System.out.printf("%-20s%-20s ", "Manager: ", department.getManager().getFirstName() + " " + department.getManager().getLastName());

System.out.printf("%-20s%-20s ", "Staff Size: ", department.getNoEmployees());

System.out.printf("%-20s%d ", "Vacation Days: ",department.getTotalVacationDays());

System.out.println();

// print the column labels for employees

System.out.printf("%-5s %-20s %-12s %-8s %-10s ", "ID",

"Employee Name", "Hire Date", "Salary", "Vac Days");

// loop over all employees in the department

for (int j = 0; j < department.getNoEmployees(); j++) {

Employee emp = department.getEmployee(j);

System.out.printf("%-5s %-20s %-12s $%6.2f %6d ",

emp.getEmployeeId(),

emp.getFullName(),

dateFormatter.format(emp.getHireDate()),

emp.getSalary(),

emp.getVacationDays());

}

System.out.println();

System.out.println();

}

}

}

Depts.txt:

A,Administration,302 E,Engineering,186 C,Construction,240 S,Sales,239 M,Marketing,250

Employees.dat:

091EAStover Nick Ap

(092CEClawson Virginia A 5093ECClawson John AH 4094EENoel Beverly A )095CEClawson Colin A

,096ESCochran Beverly A4 #097CACochran John A\ 0098ESCochran Ricky A

/099CACostello Larry A 2100CECoulter Karen AH -101CAMaudie Karen A

2102CMCowan Ronald AH

3103EECramer Ronald A 2104ESFello Ronald A4

5105ECSwanson Beverly A\

:106ESCsanyi Mary AH

3107ESCunkelman Milford A 4108CECunkelman Harry A -109ECCunkelman Jack AH .110CCCunkelman Merle Ap =111CCCunkelman Christie A\ ,112EMDechman Paul AH

9113CSDecker Richard A :114ECDecker Harry AH "115EEDellafiora Harry Ap 116ESDemangone Harry A ?117ECDemaria Rodger A\

118ESDemaria Joseph A

119CSDeyarmin Frank A 120ECDouglas John A4 121ESDouglas John B\ 122CSCampbell John B =123CACampbell John B

124EMCampbell Mark Ap 125CSDouglas William B 126CSDouglas Andrew A 127ECDouglas Andrew A

128EADouglas Robert B 129ECDrummond Douglas B9

130EMDunlap Robert B 131CADunlap Brian BR 132CAEmge Richard B 133EEHill William B 134CCSarver Harry A

135EARhea William B

136ECFarkas Frank B 137CMFaser Frank AH

138CCFedoruk Frank A

#139CSFedoruk Frank AH 140CEFedoruk John BW 141CCFerguson John B $143ESClawson Raymond @ *144CEFerguson Paul AH 145CEFerguson Paul A

146ESFerrara George B\

147CEFerrara David @p 148ECFink Harold AH 149EEFink Harold Ap .150ESMaudie Dale A 151EEMaudie Dennis AH 152ECFabin Dennis A 153ESFabin James A $154ESHarvey Paul A4

'155CSForsha Paul A\ 0156ECForsha Thomas A

)157CAForsha William A 4158CALydick William AH !159EESantella Christina A 0160CMFreed Robert AH

-161EASchaldenbrand Randy A *162ESSchaldenbrand Loy A4 $-163CSFritz Loy A\ <164CSFritz Randall AH

1165CSFabin James A &166CCFedoruk Francis A ?167EEFerguson Rex AH

4168CMFerguson Warren Ap ;169ESFabin Tama A\

6170ESFabin David AH

7171CAGalloway Michael A :172EAKwisnek Henry AH 3173EMGamble Howard Ap 8174CSGamble Barbara A

;175EEGardner Clarence A\

<176CEGarvin Nicholas A 3177ESGary Nicholas A 8178CAGaston Sam A4

179CAGeletka Clare B\ 6180CCGeorge Henry B ;181CCGibson Len B 8182EAGibson Milton Ap ?183EMGibson Joseph B

184ECGibson Joseph A

185ESGibson Charles A 186EEBruner Charles B 187CSGlass Frank B9

188ESGordish Frank B 189CEBopp David BR 190CMGrejtak David B 191EEDavis Joshua B

192CAGroft Austin A 193EAGroft Bertha B 194EMGordish Mark B

195ESGrafton Ralph AH 196ESTurnbull Jeffrey A

197EEJoyce Jeffrey AH

198CAHalberg George BW 199EEMaudie Jack B

200EEHancock Alberta @ 201CCHanna Robert AH 203CEHarper James A 204EAHarris James B\

205CCHarsh David @p &206CMHarshbarger Joel AH 207ECHebenthal Kerry Ap 208EAHebenthal Thomas A 209EMLukcik Charles AH &210EAFarkas James A +211CEStreams Judy A 212CCHendricks Rudolph A4 )213EEHenigin Mark A\ ,214CEHenigin William A

#215ESHenigin John A 0216EAHenigin Richard AH /217CSHenigin Barbara A $218CAHenry John AH

'219CEHibbs William A 220CAKrinock Clark A4 +221CMHill Franklin A\

*222EEHill Edward AH -223CSHill Ronald A (224CCStewart Emil A

-225ESHill James AH

.226CSHogue John Ap -227EEHogue Louis A\

0228ECHolby Louis AH 5229ECHoller Richard A .230ECHoller Adam AH /231EMHolmes Robert Ap (232ESHornock Andrew A 233ECHouser Patricia A\ 8234CEHoward Melvin A ;235ESHoward Frank A 4237CCHunt Kimberly A4 6238CSHunt Charles B\ 239ESHunt Norman B 240CCHuston Samuel B ;241ESHarvey Jack Ap 242ESIrvine John B 243CAIrvine Richard A #244CMJackson Allen A =245CSJackson Dale B +246CSHunt William B9 9247ECJamison Frank B 248CAJohns Barbara BR 5249ECJohnson Donald B 250EMJohnson Edward B 251CAJohnson George A 253EAJohnston Herbert B 254EEJohnston Joseph B 255CCJohnston Richard AH 256EAJohnston Ronald A 257CCJohnston Tony AH 258EMMarshall Richard BW 259CCSaunders Randy B

260CSSaunders Don @

261CEJones Don AH 262CCJohnson Don A

263ESKachonik Shirley B\ 264EEKinter James @p 265EEKirkland Elmer AH 266ESKnapko Marvin Ap

267EEKnupp Thomas A &268CCKokolis Eileen AH 269EEKoloshinsky William A

270CSKoos John A

271CEKovalchick Walter A4 272ECKrinock Ernest A\ 273CSKubala Timothy A *274ESSchweigert Dennis A 275ESVarrato Gordon AH 276ECSchweigert Gordon A 280EAKuntz Dale AH #281EAKurcsics Mike A

&282CEHall Charles A4 /283EMPeters Robert A\

(284EAPeters Gary AH 3285CSKimmel Gary A 286CSKimmel Clyde A /287ESKimmel Lesley AH

,288CSLamantia Robert Ap )290CCLanich Richard A\ -291EELawson Richard AH <292EMLeonard Richard A

1293ESLevesque Homer AH &294ESLong Homer Ap ?295CABrown Homer A

4296CALong Russell A\ ;297EMLongenecker Russell A

6298CSLosier Kenneth A

7299EELosier Helen A4 :300EELosier Helen B\ 3301CSWertz Ronald B 8302CATrefelner James B

;303CALukcik Andrew Ap

<304CCLukcik Garry B 3305CCLukcik William A 8306EALukcik Steve A

307CMLukcik Matthew B 6308CCLukcik Ellen B9 ;309ESShannon Ellen B 8310CELutz Cheryl BR ?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!