My objective is make a game program for my cs class. So my game is like this:
You input a word and then input another word which starts from the last letter of the first word. The program check if the word has been used before and if the last letter matches the first letter. My bugs are:
editing/incrementing string names ex: (word + "i++")
line of code for last letter in a string ex: equals(words.substring(last)
very noob question: in an arraylist: what is words[0]? correct syntax
does this
(word + "i++").equals(words)
compare wordx to each and every variable in the arraylist words?
import javax.swing.JOptionPane;
import java.util.ArrayList;
public class Words
{
public static void main(String[] args)
{
ArrayList<String> words = new ArrayList<String>();
String word1 = JOptionPane.showInputDialog("Please Enter a String");
WordCheck game = new WordCheck(words);
game.add2Array(word1);
System.out.println(word1);
for (int i = 0; game.condition(true); i++)
{
String (word + "i++") = JOptionPane.showInputDialog("Please Enter a String");
if (word2.substring(0).equals(words[i].substring(last)) || (word + "i++").equals(words))
{
game.condition(false);
}
else
{
game.add2Array(word + "i++");
System.out.println(word + "i++");
}
}
System.out.println("Game Over!");
}
}
import java.util.ArrayList;
public class WordCheck
{
ArrayList<String> wordsUsed;
public WordCheck(ArrayList<String> words)
{
words = wordsUsed;
}
public void add2Array(String word1)
{
wordsUsed.add(word1);
}
public boolean condition(boolean value)
{
return value;
}
}