There are multiple stacks of pogs with images on the bottom, so there will be ma
ID: 3827645 • Letter: T
Question
There are multiple stacks of pogs with images on the bottom, so there will be many pogs with the same picture.
The person starts off with 13 pogs in his/her hands.
(Question) How would the algorithm look in java-code for the text below?
[On each round of the game, the person takes a pog from the stack of pogs.
Every time the person takes a pog from the stack, a pog from the person's hand must be removed and thrown away.
If the taken pog from the stack is the same in the person's hand, the person must continue to take pogs from the stack,
until the taken pog from the stack does not have the same image as the one's in the person's hand.]
Explanation / Answer
List<String> pogsInHand = new ArrayList<String>();
Stack<String> stackOfPogs = new Stack<String>();
/* TODO : Add 13 new pogs to the above list */
/* TODO : Add pogs to the above stack */
while (true) {
String pogFromStack = stackOfPogs.pop();
/* search for the above obtained pog, from the pogs in person's hand
* */
boolean isFound = false;
for (String pog : pogsInHand) {
if (pog.equals(pogFromStack)) {
continue;
}
}
if (!isFound) {
break;
}
pogsInHand.remove(0);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.