Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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 While

Explanation / 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));

}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote