• Post Reply Bookmark Topic Watch Topic
  • New Topic

Linear Search Problem  RSS feed

 
Tim Walsh
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could somebody please explain this method for me in a bit of detail

 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Walsh wrote:Could somebody please explain this method for me in a bit of detail


Welcome to the Ranch, Tim!

A few things you should know, to make your time here more productive:

1) UseAMeaningfulSubjectLine(⇐click) so people will know at a glance what your question is about.

2) TellTheDetails.(⇐click) What specifically are you confused about in that code? (If your answer is "all of it", then start here: http://docs.oracle.com/javase/tutorial/getStarted/cupojava/index.html. And continue here: http://docs.oracle.com/javase/tutorial/java/index.html.)

3) When posting code, please UseCodeTags(⇐click) so it will be readable.

Good luck!
 
Tim Walsh
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok will do sorry
 
Saurabh Pillai
Ranch Hand
Posts: 541
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Walsh wrote:Could somebody please explain this method for me in a bit of detail

public int search(String EmployeeNumberIn)
{
for(int i = 0; i < total; i++)
{

Employee employeeAcc = employees[i];
String employeeNum = employeeAcc .getEmployeeNumber();

if(employeeNum .equals(EmployeeNumberIn))
{
return i;
}

} return -999;
}


I think, employees is an array of Employee, and total is length of that array. Also, I think they are declared as class level variables as I do not see them declared in search method.

The purpose of this method looks like searching an employee by employee number. It(for loop) goes through each employee record, retrieves employee number and compare it against inputted employee number(EmployeeNumberIn). If it finds the match, it returns position in array otherwise returns -999, which I think is treated as error code.

This code looks like small part of a bigger program. Did you run that program? What you do NOT understand? Ask specific question.
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have corrected the code tag problem and (I think) the title. It looks rather better now
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!