• Post Reply Bookmark Topic Watch Topic
  • New Topic

Must Punch-In Before Punch-Out  RSS feed

 
Anakela Bella
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey there. I'm trying to figure out how to read my text file so that an employee with a specified employee ID number must have a record of having punched-in before they can punch-out of the system. Here is what I'm working with so far:

Any help is greatly appreciated. Thank you in advance!
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does this code do now, and how is that different from what you expected it to do? To put it another way: do you have a concrete question about it?
 
Jacob Draper
Ranch Hand
Posts: 35
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to read and write to a text file, I think a stream would be what you're looking for right?

http://docs.oracle.com/javase/tutorial/essential/io/charstreams.html
 
Anakela Bella
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:What does this code do now, and how is that different from what you expected it to do? To put it another way: do you have a concrete question about it?
Hi, Ulf. As of now, it does nothing. I have an error that displays bad operand types for binary operator '&&' on line 84, and another error on line 86 that says incompatible types: TimeClock cannot be converted to List<TimeClock>. It might help to see the other file from which I'm pulling some of these methods. It is as follows:
 
Anakela Bella
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jacob Draper wrote:If you want to read and write to a text file, I think a stream would be what you're looking for right?

http://docs.oracle.com/javase/tutorial/essential/io/charstreams.html
Hi, Jacob. Thanks for the link. I'm taking a look at the tutorial that it leads to now, though I'm not sure if it's exactly what I'm looking for. (Though it might be!) Currently, I'm not really looking to write anything to a text file, except for after an employee clocks in or out, which is working so far. I want to be able to read what is in my timeclock.txt file to see if someone with a specific ID number has already punched in or not. If they have, I want them to be able to punch out and not punch in again. If they have not, I want them to have to be directed back to the top of the while loop. It's making me just a little bit crazy.
 
Anakela Bella
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No progress. Can anyone help? I'm getting pretty desperate. I know that I have to compare columns[0] and columns[2] from my timeclock.txt file to the user's input to see if someone has punched in yet, or if they have punched out, but I don't know how to do that. Any help is greatly appreciated. While playing with my current code, I did the following:

I am still getting the same errors as mentioned to Ulf. I am completely stumped.
 
Jacob Draper
Ranch Hand
Posts: 35
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
could you post the errors that you are getting? thanks

Also, Post all of your code and all of your classes and I will give my best shot at helping you.
 
Anakela Bella
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not so much an error as it is NetBeans giving me the big red stop sign with the exclamation point telling me that the code line if(t.getPunchInOrOut() && choice.equalsIgnoreCase("i")) has bad operand types for binary operator '&&' because the first type of method here is String, and the other is Boolean. Then it tells me that the line within that if statement (timePunches = t;) has incompatible types: TimeClock cannot be converted to List<TimeClock> and pretty much ignores that whole bit of code. I will post the classes that are relevant to this class as I have sixteen different classes in the entire application.





I apologize for the length. Is it possible to use List<TimeClock> readTimePunches() to achieve what I need as the columns are already split there?
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anakela Bella wrote:
the code line if(t.getPunchInOrOut() && choice.equalsIgnoreCase("i")) has bad operand types for binary operator '&&' because the first type of method here is String, and the other is Boolean.

&& is a boolean operator - it only works when the operands are both boolean values. One of yours is a String.
What do you think would be the result of

Anakela Bella wrote:Then it tells me that the line within that if statement (timePunches = t;) has incompatible types: TimeClock cannot be converted to List<TimeClock> and pretty much ignores that whole bit of code

timePunches has the type List<TimeClock> and t has the type TimeClock. You can't assign one to the other.
What are you actually trying to do in that piece of code ?
 
Anakela Bella
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joanne Neal wrote:
What are you actually trying to do in that piece of code ?
I'm trying to get the TimeClockApp to ensure that an employee who has clocked in cannot clock in again, & ensure that an employee who hasn't clocked in cannot clock out. Sadly, I am quite lost, and am doing it wrong.
 
Jacob Draper
Ranch Hand
Posts: 35
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One bit that may be contributing to your problem,

You do this:





but don't seem to assign it to anything so is it actually doing anything?


Also, if you are having trouble with:



have you tried simply printing some of those values before hand to make sure that everything is what it seems?

example: and so on....

if everything seems logical after testing that then you know that statement isn't where the problem lies.
 
Anakela Bella
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, I don't think timeClockDAO.readTimePunches(); is doing anything, but I'm not sure I know how to assign it to something.

In terms of printing the values beforehand, I am not sure what you mean. I know that the employeeID that the user types in is correct, because my code won't allow the user to input a non-existant ID, and I know that this ID is recording properly because it shows in the text file. It is the same with the user's choice of I or O. (Maybe I am misunderstanding what you are asking. Sorry!) I'm just confused on how to compare columns[0] in the timeclock.txt file to the user's choice of either I or O, and how to compare columns[2] in the text file to the user's inputted employeeID in order to see if they have already clocked-in or must do so in order to clock-out.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!