Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Complete question This question concerns a Java program to set up and maintain information about programmers who work for the Milton Software Mine. Details about

Complete question

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.

Launch BlueJ and open the project.

a.Open the Programmer class, which contains declarations for instance variables, a partially completed constructor, and some getter and setter methods. The purpose of each instance variable is indicated in the comments accompanying the declarations. The instance variable name is initialised by the constructor. Programmer ID numbers are to be allocated on a sequential basis as each Programmer object is created: the first Programmer whose details are read from the file should have the number 1, the second 2, the third 3, and so on.

i.The ID to be allocated to the next new instance of Programmer is to be held in a private static variable of the Programmer class called nextId. Add a single line of code to the Programmer class to declare this class variable and initialise it to 1.

ii.Add code to the constructor to set the id instance variable of a newly created Programmer object to the value of the class variable nextId. Then increment the value held by nextId by 1, so that it will hold the number of the next Programmerobject to be created.

b.Create a class called Payroll in your TMA03_Project_Q4_Sol project.

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 suitable OUFileChooser 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.

.

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 Programmerto 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().

Note: Expert have to use bluej for solution.

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 Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions

Question

Assemble short, logical paragraphs

Answered: 1 week ago