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 06-14-2008, 06:52 PM
Member
 
Join Date: May 2008
Posts: 4
hezfast2 is on a distinguished road
vector list search
Hello, I've written a multiple choice question version of a Hangman game. Everything works 'except' I don't want questions asked more than once. I've come up with a search algorithm, but I obviously don't have it correct, or I'm going wrong somewhere, It compiles but the questions still repeat. here's what I have so far: Any help or advice would be greatly appreciated.
Code:
questionNum = (int)(Math.random() * 10); while (isUsed) { searchResult = seqSearch(usedList, questionNum); if (searchResult == -1) { isUsed = false; }//end if else questionNum = (int)(Math.random() * 10); usedList.addElement(questionNum); }//end while QuestionInfo curQues = new QuestionInfo(questionObj[questionNum]); displayQuestion(questionObj, curQues, questionNum);
Code:
public int seqSearch(Vector<Integer> usedList, int questionNum) { boolean found = false; for (Integer num : usedList) if (num == questionNum) { found = true; break; } if (found) return 1; else return -1; }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-14-2008, 07:39 PM
Senior Member
 
Join Date: Jun 2008
Posts: 178
Fubarable is on a distinguished road
Personally, I'd not use a Vector, but instead would use a ArrayList of Question, and then call Collections.shuffle(...) on my ArrayList. Then with a shuffled list simply loop through the list asking questions.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 06-14-2008, 07:48 PM
Senior Member
 
Join Date: Jun 2008
Posts: 178
Fubarable is on a distinguished road
Cross-posted in the Sun Java forums. Please don't cross-post unless you are planning to upset folks in the various fora.
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
Search a object in a vector TalhaS New To Java 2 04-30-2008 03:05 PM
How to Search a List in Java Java Tip java.lang 0 04-16-2008 11:38 PM
Vector help king_arthur New To Java 3 01-22-2008 08:33 PM
Vector capacity Java Tip Java Tips 0 11-04-2007 06:58 PM
array vs Vector paty New To Java 1 08-02-2007 08:07 PM


All times are GMT +3. The time now is 09:17 AM.


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