I\'m having trouble undersanding how to determine when a button is suppose to be
ID: 3739109 • Letter: I
Question
I'm having trouble undersanding how to determine when a button is suppose to be marked with a white, meaning the guess is on the board but not in the right spot.
import java.awt.Graphics;
import java.awt.Image;
import java.util.ArrayList;
import java.util.List;
import gui.ImageLoader;
class Guess
{
private List<Integer> color_ids;
private int guess_id; //the number of this guess (from 1 to 8)
private int[] result; //the number of black and white buttons, respectively
public Guess(int guess_id)
{
this.guess_id = guess_id;
color_ids = new ArrayList<Integer>();
result = new int[2];
}
public Guess(Guess copy_guess)
{
assert copy_guess.isFull() : "Guess not complete.";
this.guess_id = copy_guess.guess_id;
color_ids = copy_guess.getGuessColorIDs();
result = new int[2];
result[0] = copy_guess.result[0];
result[1] = copy_guess.result[1];
}
public int getNumBlack()
{
return result[0];
}
public int getNumWhite()
{
return result[1];
}
//comparing two guesses to determine the number of black and white buttons
public int[] reportResult(Guess other_guess)
{
//guesses must have all four positions assigned a color first
assert isFull() && other_guess.isFull() : "Guesses not complete.";
int[] result = new int[2];
//need a copy of these as will be removing elements
List<Integer> other_guess_ids = other_guess.getGuessColorIDs();
List<Integer> current_guess_ids = getGuessColorIDs();
int black_count = 0;
int white_count = 0;
//easy to check for black buttons
for (int i = 0; i < other_guess_ids.size(); i++)
{
int other_guess_id = other_guess_ids.get(i);
int current_guess_id = current_guess_ids.get(i);
if (other_guess_id == current_guess_id)
{
black_count++;
other_guess_ids.remove(i); //award a black button and remove those elements
current_guess_ids.remove(i);
i--; //accounts for shifting of elements after removal
}
}
//re-analyze for white buttons
//DO THIS
result[0] = black_count;
result[1] = white_count;
return result;
}
Explanation / Answer
this question is divide dinto two parts ;
first you import the class button in JButton package .
you override this abstraact class into array whether they use two choices .for example see that code you use as public class instead of using abstract class ...
public Guess(Guess copy_guess)
{
assert copy_guess.isFull() : "Guess not complete.";
this.guess_id = copy_guess.guess_id;
color_ids = copy_guess.getGuessColorIDs()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.