• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Linear Search Problem  RSS feed

 
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

 
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
 
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.
 
Marshal
Posts: 60803
190
  • 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
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!