Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This question has been asked previously, but has not been successfully answered... This question concerns a Java program to set up and maintain information about

This question has been asked previously, but has not been successfully answered...

This question concerns a Java program to set up and maintain information about programmers who work for the Milton Software Mine. Details about the programmers names, their pay grades and the hours they have worked over the last six months are recorded in the file employees.txt, in the format: Firstname Secondname,paygrade,hours,hours,hours,hours,hours,hours

The employees names are separated by a space; the pay grade is an integer (1, 2 or 3) and then there are six integer figures representing hours worked in each of six months. The items are separated by commas, and there are no spaces around the commas. There is a line like this in the file employees.txt for each employee.

b.Create a class called Payroll in your IDE

i.Add a line of code to the Payroll class to declare an instance variable programmers, to reference a list of Programmer objects. Next add a line of code to the Payroll constructor to assign a new instance of ArrayList to programmers.

ii.In the Payroll class, add a method with the header private int computePay(Programmer p). The method should return the programmers grade multiplied by the number of hours they worked. For example, if the programmers grade is 2, and the total hours they worked is 6, the method should return 12.

iii.In the Payroll class write a public instance method called readEmployeeData() that takes no arguments and returns no value. The method will need to read from the file employees.txt, which can be found in the project folder for this question, and which contains the name, grade and hours worked for each of the programmers in comma-separated format, as explained at the beginning of this question. The code for the method should do the following: ?Use a FileReader method to allow the user of the program to locate the file to be read. ?Construct a buffered file reader object to read the filename the user identified. ?After each line of the file is read, use a Scanner object to extract the programmers data from it. ?For each line in the file a new Programmer object should be created and its instance variables set as follows: ?? name should be set using the first token from the data for the current employee, when constructing the programmer object. ?? grade should be set based on the next value from the line. ?? hours should be set to the total hours worked for the current employee. ?? To set the pay, compute the total pay the programmer is due using the method computePay() you wrote in part (ii). Use this value to set the programmers pay. ?Finally, the instance of Programmer youve created and initialised, as above, should be added to the programmers list. In order to gain full marks you will need to ensure that the input file is properly closed by your method and also that it handles possible exceptions sensibly, e.g. if the user chose the wrong file to be read. You can test your code by executing: Payroll proll = new Payroll(); proll.readEmployeeData(); in the IDE. Having executed the method, you can use the inspector to inspect proll and check that its instance variable programmers references a list of the Programmers created from the data in the text file, with correct names, pay grades and pay.

iv.Write a toString() method for the Programmer class, to return a string describing each programmer, as follows: Sleepy Servlet (Grade 1, ID 1) Hours 351 Pay 351 The string contains the programmers name, grade, ID (in parentheses), hours worked and pay. You will test this method in the next part.

v.Write a public method for the Payroll class called showPayroll() that takes no arguments and returns no value. The method should iterate over programmers, and print out the string representation of each programmer.

c.To create a list of highest earning coders, the software mine wants the list of programmers organised in order of their pay from lowest to highest and they would like this information written to an output file called "payrollResults.txt".

i.So that you can sort programmers by pay, modify the Programmer class so that it implements the Comparable interface. To do this you will need to modify the class header and write a compareTo() method that will allow instances of Programmer to be sorted by ascending order of the value stored by their pay instance variable.

ii.Now write the writePayroll() method for Payroll. The method should be public, take no arguments, and return no value. The method should sort the receivers list of programmers from smallest to largest pay. The resulting sorted programmer list should be written to the text file "payrollResults.txt", which should be saved in the project folder for this question. The program user will need to identify the appropriate location to store the file. The output for each programmer to be written to the file is its string representation as produced by toString(). Test this method so that you create the file "payrollResults.txt" in the required location. The resulting file should contain lines similar to the following, sorted by order of increasing pay:

Grumpy Gopher (Grade 2, ID 2) Hours 123 Pay 246

Doc Datamine (Grade 1, ID 4) Hours 312 Pay 312

Sleepy Servlet (Grade 1, ID 1) Hours 351 Pay 351

MANY THANKS

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Mannino Michael

5th Edition

0983332401, 978-0983332404

More Books

Students also viewed these Databases questions

Question

What does 4/15, net 30 mean?

Answered: 1 week ago