I am trying to make a project for school where I have to guess a word. If the word is right, it gets a red dot and if it's in there somewhere, it will get a yellow dot and if there is no similarity, it will get a gray dot. I have made an array that contains the word that has to be guessed that's named array and an array that contains the word being guessed having one character in each array entry.
I thought some setup like this would be viable:
place = 0; // The tekenaarextra and checkletters are not the problem that's just the result that happens if they are true
while(place <5){
if(array[place] == array2[place]){
System.out.println(array[1]);
checkletters(place,1,Color.RED);
tekenaarextra2();
place ++;
}else if( array[0] == array2[place] || array[1] == array2[place] || array[2] == array2[place] || array[3] == array2[place] || array[4] == array2[place] ){
checkletters(place,1,Color.YELLOW);
tekenaarextra2();
place ++;
}else{
checkletters(place,1,Color.GRAY); // this is just a method to draw the dots.
tekenaarextra2();
place ++;
}
}
However, whilst using this I get error messages and I do not quite know how to really compare separate entries from the arrays without putting them into different Strings which is a lot of separate work.
For example, I got String[] array = {a,p,p,l,e}, and I got String[] array2 = {p,l,a,t,e}
I want to then compare the first entry from the array2 to the first one of the array and if they're the same character, I should execute a certain command to draw a dot if it's not so, else if it should compare the first entry from array 2 to all the other entries to see if it needs a yellow dot. If it all tests false and it doesn't contain any of them, it should just have an else that leads into drawing a gray dot. And this over 5 times to compare all the letters of array 2, but that can be done simply by a while statement.
Simplified version of what I need to do
if(array[0]==array2[0]){ // if the first letter of guessed word is the first letter in the mystery word
drawreddot();
} else if( array[0] == array2[1] || array[0] == array2[2] || array[0] == array2[3] || array[0] == array2[4]){
// if the letter guessed isn't in the same place but in the mystery word on another place
draw yellow dot
}else{ // if it doesn't compare to any of the entries
draw gray dot
}
String. A string's characters can be accessed in the same way that an array's elements can be accessed)