Workiva Interview Question: Write a class that simulates ... | Glassdoor

Interview Question

Software Engineer () Interview Ames, IA

Write a class that simulates a deck of cards that

  implements a shuffle method and is able to deal a random card out of the deck.

Interview Answer

1 Answer


I wrote a class for the Deck and a class for the Cards. Inside the deck class, I made a nested for loop that would iterate through each of the suits of the card and the numbers and then wrote them to an array. Inside the deal method, I used a random number generator that would pick a card, delete the element, and shift all remaining elements over so that there were no null spaces in the middle of the array, and then reduce a variable that kept track of the number cards in the deck. Inside the Card class, I made a constructor that would initialize a new card with a suit and number and then made getter methods to return the card.

Interview Candidate on Oct 5, 2018

Add Answers or Comments

To comment on this, Sign In or Sign Up.