December 11th, 2012, 05:22 AM
-
Help with Countdown Program
HI I'm currently working on a program to simulate the TV show countdown. Basically I need it to ask for 8 vowels or consonants then display the largest matched words from a seperate text file. I've got it working up until displaying the words, i can;t get it to show up the right thing. Any help would be appreciated.
This is what I've got for the matched words part:
public static void matchWords(){
String countdownLetters = userLetters.toString();
//words
for(int i=0; i <wordLists.length - 1; i++){
// letters in word
int wordLength = wordLists[i].length() - 1;
String word = wordLists[i];
int matchedLetters = 0;
System.out.print(countdownLetters);
for(int j=0; j<wordLength; j++){
char letter = word.charAt(j);
if(countdownLetters.indexOf(letter) >= 1){
matchedLetters = matchedLetters + 1;
if(matchedLetters == wordLength){
//matched word
System.out.println(word);
December 11th, 2012, 08:10 AM
-
i can;t get it to show up the right thing
Please explain. What does the program display now? What should it display?
Please edit your post and wrap your code with code tags
[code ] (without space after e)
<YOUR CODE HERE>
[/code]
to get highlighting and preserve formatting.
December 11th, 2012, 10:18 AM
-
Sorry, It displays a list of words with any matching letter, when it's supposed to show the longest word containing the chosen letters
Code:
public static void matchWords(){
String countdownLetters = userLetters.toString();
//words
for(int i=0; i <wordLists.length - 1; i++){
// letters in word
int wordLength = wordLists[i].length() - 1;
String word = wordLists[i];
int matchedLetters = 0;
System.out.print(countdownLetters);
for(int j=0; j<wordLength; j++){
char letter = word.charAt(j);
if(countdownLetters.indexOf(letter) >= 1){
matchedLetters = matchedLetters + 1;
if(matchedLetters == wordLength){
//matched word
System.out.println(word);
December 11th, 2012, 10:26 AM
-
Can you post the program's output and explain what is wrong with it and show what it should be?
Please edit the post and format the code. Not all statements should start in the first column. Nested statements should be indented 3-4 spaces.