• 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

Linear Search Problem

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok will do sorry
 
Ranch Hand
Posts: 541
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have corrected the code tag problem and (I think) the title. It looks rather better now
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic