Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-15-2008, 03:46 AM
Member
 
Join Date: Apr 2008
Posts: 6
adelgado0723 is on a distinguished road
Searching an arraylist
The assignment requires that I write a program to update, maintain and query students' records on an ongoing basis. It requires a few things, but there's one in specific that I'm stuck on.
This is my Student class:
Code:
public class Student { private String id, firstname, lastname; Student(String i, String f, String l) { id = i; firstname = f; lastname = l; } String getid() { return id; } String getfirstname() { return firstname; } String getlastname() { return lastname; } }
This is my Admissions class:
Code:
import java.util.ArrayList; public class Admissions { Student s; ArrayList<Student> list; int index; boolean found; //2a Admissions() { list = new ArrayList<Student>(); } //2b void add(Student s) { list.add(s); } //2c int size() { return list.size(); } //2d boolean isempty() { return list.isEmpty(); } //2e void search(String key) { if (list.s.getid().equalsIgnoreCase()) { ; } //Prof. didn't tell us how to do this. We need to figure it out, but I think it's with a while loop. } //2f Student remove(int i) { return list.remove(i); } }
My problem is under 2e. I need to "given an id number, locate that record on the list"
Thanks!

Last edited by adelgado0723 : 04-15-2008 at 03:52 AM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-15-2008, 02:09 PM
Chris.Brown.SPE's Avatar
Member
 
Join Date: Apr 2008
Location: State College, PA
Posts: 50
Chris.Brown.SPE is on a distinguished road
Send a message via AIM to Chris.Brown.SPE
Here is the loop to go through each student and check their id against the key. If this doesnt help, it should get you close enough to get the rest of your logic. Let me know.

Code:
for (Student temp : list) { if (temp.getid()==key) { found=true; } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java Project Trouble: Searching one ArrayList with another ArrayList BC2210 New To Java 2 04-21-2008 12:43 PM
recursively searching through arraylists newtojava7 New To Java 1 03-17-2008 03:36 AM
searching within a JList newtojava7 New To Java 1 03-10-2008 01:12 AM
searching nalinda New To Java 3 12-06-2007 03:56 AM
Searching XML file using DOM simon XML 3 08-01-2007 05:38 PM


All times are GMT +3. The time now is 08:16 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org