Problem #3 Shuffle Up And Deal Download this file which has the start of a class
ID: 3855581 • Letter: P
Question
Problem #3 Shuffle Up And Deal Download this file which has the start of a class representing a "card shoe the actual name of the things that casino dealers use to help shuffle and deal cards. For this problem, you will need to complete the shuffle method by implementing the following algorithm Move the first half of cards into firstHalf This may or may not be done in one line of code Move the remaining elements in cards into secondHalf This may or may not be done in one line of code While there are elements in firstRalf Remove the element at the start of first Balf and add it to cards Remove the element at the start of secondHalf and add it to cards EndWhile If second Half has any elements remaining Remove the element at the start of secondHalf and add it to cards End WhileExplanation / Answer
Given below is the implementation of the algorithm described. Please don't forget to rate the answer if it helped. Thank you very much.
package edu.sbu.cse;
import java.util.List;
public class CardShoe {
private List<PlayingCard> cards;
public CardShoe(List<PlayingCard> originalList) {
cards = originalList;
}
public void shuffle(ListGenerator gen) {
List<PlayingCard> firstHalf = gen.createNewList();
List<PlayingCard> secondHalf = gen.createNewList();
int half = cards.size() / 2;
//add first half cards to firstHalf
for(int i = 1; i <= half; i++)
firstHalf.add(cards.remove(0));
//add remaining cards to secondHalf
secondHalf.addAll(cards);
cards.clear(); //clear the cards since we added both the halves
while(!firstHalf.isEmpty())
{
cards.add(firstHalf.remove(0));
cards.add(secondHalf.remove(0));
}
//if any card is in secondhalf
if(!secondHalf.isEmpty())
cards.add(secondHalf.remove(0));
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.