• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Compare User Input to Text File

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Heyo. I'm attempting to compare user input to a text file that I have set up whenever the user types in an employee ID number. I want to be able to tell the user that either the ID number is valid, or that it is not valid and must be re-entered by comparing it to the employee.txt file, and then record the valid ID number to the timeclock.txt file. Right now, I'm recording the next available employee ID number instead of the one I typed in. The output of the program looks like this:

(I typed 1 as the employee ID.)
I hope I'm close to figuring this out. Any help is greatly appreciated. The codes that apply to this part of my application are as follows (I apologize for the length!):

AND
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In lines 54 and 79 you are calling employeeDAO.readEmployees(). That method returns an ArrayList<Employee>. But you're not doing anything with the return value; you're calling the method and you're not assigning the result to a variable, so the result is thrown away.

You need to assign the result of the method call to a variable of the appropriate type. Most likely that should be the variable timeClock.

The employeeDAO also has a method getEmployee(int employeeID) that will return an Employee if the ID is valid, or null if the ID is not valid. That's what you will need to use to check if the employee ID is valid.
 
Anakela Bella
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jesper de Jong wrote:In lines 54 and 79 you are calling employeeDAO.readEmployees(). That method returns an ArrayList<Employee>. But you're not doing anything with the return value; you're calling the method and you're not assigning the result to a variable, so the result is thrown away.

You need to assign the result of the method call to a variable of the appropriate type. Most likely that should be the variable timeClock.

The employeeDAO also has a method getEmployee(int employeeID) that will return an Employee if the ID is valid, or null if the ID is not valid. That's what you will need to use to check if the employee ID is valid.

Thank you, Jesper. I will keep working on this until I get the correct methods to return the correct results, and will post the resolved code when I figure out what it is. Thanks again!
 
Anakela Bella
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, so I attempted to use timeClock.add(employeeDAO.getEmployee(employeeID)); after using employeeDAO.readEmployees(), but had to initialize an employeeID in the main method of the TimeClockApp to make it even appear without an error message. However, instead of getting an employeeID recorded in my timeclock.txt file, I am getting "null," even when the employeeID exists in the employee.txt file.
 
Anakela Bella
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Still no progress. If anyone else can help, I would be very grateful. Apparently, I have to set the read-in value of what the user inputs at line 51 to employee ID, but I have no idea how to do that. Can anyone help?
reply
    Bookmark Topic Watch Topic
  • New Topic