SunQuest
 
           Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old April 27th, 2008, 03:20 PM
albear albear is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 10 albear User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 32 m 27 sec
Reputation Power: 0
Finding object by searching for a string

i have my find method, which is meant to find a boat by searching for the idnumber of a row/pedaloat with the same string as the one i put in.

public Boat findBoat(String IDNumber) // finds all available boats of a certain type input by user
{
for (int i=0; i < numPedalBoats; i++)
{
PedalBoat idn = thePedalBoats.get(i);
if (idn.getIDNumber().equalsIgnoreCase(IDNumber))
{
System.out.println(thePedalBoats.toString()); // how do i get it to print out the boats details
}
return idn;
}
for (int i=0; i < numRowBoats; i++)
{
RowBoat idn = theRowBoats.get(i);
if (idn.getIDNumber().equalsIgnoreCase(IDNumber))
{
System.out.println(theRowBoats.toString()); // how do i get it to print out the boats details
}
return idn;
}

return null;
}
its meant to find a pedalboat or a rowboat depending on what id number i enter.

RowBoat andy = new RowBoat(null, "012345", 0, false, 0, "Andy", 10, 0);
System.out.println("Testing andy toString method:");
andy.displayDetails();
BoatHireCompany Bridge = new BoatHireCompany(10, 10);
Bridge.addRowBoat(andy);
Bridge.findBoat("012345");

so ive done this because im not sure how else to do it but it dosent work.
if you need more info just tell me but any help would be great thanks

Reply With Quote
  #2  
Old May 5th, 2008, 04:45 PM
ricardoz ricardoz is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Location: Montevideo, Uruguay
Posts: 9 ricardoz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 50 m 34 sec
Reputation Power: 0
As a first tip, you have several return statements in the same method. That is usually a bad idea, since it obscures your code and is very error prone.

You should define a local variable and set it with what you want to return, and use a single return statement at the end of your method.

Other than that, your method has a return statement inside the first "for" loop, that will prevent the rest of the method to be executed...

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > Finding object by searching for a string


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway