Hello! I am currently working on a program that will read from a .txt file to create an arraylist. I will be working with the objects in the list to perform computations and display the data. The .txt file is in the following format:
lastName firstName hoursWorked hourlyRate
With no delimiters. I've messed with this thing way too much in the last 12 hours (only day off for the week ) so variable names etc have changed often. If there are errors in the program due to that I profusely apologize! Any help would be greatly appreciated.
At present the error I am receiving is "error: constructor GrossPayService in class GrossPayService cannot be applied to given types". I understand what the error means, but not how to fix it. There may be other errors as well, but at present that is all my compiler is giving me.
What trouble are you having in deciding how to change your GrossPayService constructor declaration(s) or the arguments to the constructor on line 21 to fix this error?
As an aside, an addEmployee that takes arguments of the employee to add makes sense, but seeing it read one or more employees from a file doesn't. I would do that in a readEmployees(String fileName) or some such thing.
That looks like a class written specifically to sort out the problem reading from the file. That is a good idea. Agree that the error message suggests you are passing the wrong types for the constructor. Please show us the constructor for the gross pay class.
Has somebody told you they want an LF character? If not, avoid \n. Use printf and %n instead.
Also try to reduce the number of print calls. You will get a slight performance enhancement if you can join two print calls into one.
Jacob Anawalt wrote:As an aside, an addEmployee that takes arguments of the employee to add makes sense, but seeing it read one or more employees from a file doesn't. I would do that in a readEmployees(String fileName) or some such thing.
@Cody: Another point:
You don't need to enclose code in a try...catch block just because it throws a checked Exception.
Your block doesn't add any value at all, because all it does is swallow an Exception and exit your program with a message that is probably far less informative than the original stacktrace would be. Also: you don't close() the FileReader.
My advice - either:
1. Use a try-with-resources block, and re-throw anyIOException as an IOError, containing the original Exception as a 'cause'.
2. Add 'throws IOException' to your addEmployee() method declaration, and remove the try...catch block altogether.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
That can't possibly be all the code, there must also be a class called GrossPayService as Jacob has pointed out (It may be the class was supplied by your teacher rather than you writing it). Also please post the full compiler message as it gives us more information on where the problem is occurring than the snippet you have supplied.