I wrote a program calling a few different methods and it is all working, but I wanted to get feedback towards my own comments on the code. I read a link (posted just below) to help get me started on the path of proper documentation.
Tips for maintainable Java code
In supplement to general feedback, I would like specific comments on if any of the code is well explained, or if any descriptions are vague. Through out the program there are various description lines which I typically draft before writing my code, each only a few words, and they act as the total of my design process. Do these little things just get in the way or are they helpful?
public class CouponCollector { public static void main(String[] args) { // 1. Display the purpose of the program for the user System.out.print("This program draws four cards until each suit is present." + " After each\n draw, the deck is reshuffled with the drawn cards.\n"); int[] deck = countingArray(52); //Grabbing a unopened deck of cards int[] suits = countingArray(4); /* 2. Place holder array for the four suits (0-3) *this will be used in the divideSetMethod. *(52 cards) / (13 cards per set) = Q + R * Q = suit of card */ int[] rank = countingArray(13); /* 3. Place holder array for the 13 ranks *this is currently reserved for future *modification (2/1/2014). */ int numberOfDraws = 0; //4. Purpose of program is to test the number of draws //5. until a complete set of each suit is formed boolean match = false; //6. reshuffle deck and draw Until all four suits are drawn together. while (match == false) { //7. Shuffle deck deck = shuffleArray(deck, 3); //8. Draw cards from deck numberOfDraws++; int[] drawnCards = stackDrawlArray(deck, 4); System.out.print(numberOfDraws + ": "); for (int printDrawnCards: drawnCards) { System.out.print(printDrawnCards + " "); } System.out.println(""); //9. Determine if one of each suit is present match = divideSet(drawnCards, suits, 13); } System.out.println("Number of matches until complete collection: " + numberOfDraws); } //10. countingArray generates an array of elements each incremented by one public static int[] countingArray(int numberOfElements) { //11. initialize array int[] countingArray = new int[numberOfElements]; //12. Fill array in increments of 1; for (int i = 0; i < numberOfElements; i++) countingArray[i] = i; //13. Return array return countingArray; } //14. arrayMultiplier multiplles the element of any array by a number public static int[] arrayMultiplier(int[] array, int multiplier) { //15. Multiply the array for (int i = 0; i < array.length; i++) array[i] = (array[i] * multiplier); //16. Return array return array; } //17. shuffleArray randomly sorts the elements of an array public static int[] shuffleArray(int[] array, int numberOfShuffles) { //18. Shuffle array for (int shuffle = 0; shuffle < numberOfShuffles; shuffle++) { int swap; int swapPosition; for (int i = 0; i < array.length; i++) { swap = array[i]; swapPosition = (int)(Math.random() * array.length); array[i] = array[swapPosition]; array[swapPosition] = swap; } } //19. Return shuffled array return array; } //20. stackDrawlArray collects numbers from top of an array public static int[] stackDrawlArray(int[] array, int drawCount) { //21. Prepare array to contain elements int[] topOfStack = new int[drawCount]; //22. Take top of the elements for (int i = 0; i < drawCount; i++) topOfStack[i] = array[(array.length - 1 - i)]; //24. Return top of stack return topOfStack; } /*25. modulusDivideSet allows the creation of a dynamic sorting technique of integers. *The suit of a card is sorted by: suit = (int) array[0-51] / divider(13) = quotient *Quotient indicates which suit the card is: * (Q = 0 = Spade), (Q = 1 = Heart) * (Q = 2 = Club), (Q = 3 = diamond) */ public static boolean divideSet(int[] array, int[] modulusParameters, int divider) { //26. Generate a boolean array for comparison boolean[] modulusPass = new boolean[modulusParameters.length]; //27. Compares an array to its modulus parameters for (int i = 0; i < array.length; i++) { int modulusCheck = (int) (array[i] / divider); for (int j = 0; j < modulusParameters.length; j++) { if (modulusPass[j]) continue; if (modulusCheck == modulusParameters[j]) modulusPass[j] = true; } } //28. Check to see if modullusPass are all true indicating a complete collection for (int k = 0; k < modulusParameters.length; k++) { if (modulusPass[k]) continue; //29. One of the checks did not pass. else return false; } //30. All of the checks passed return true; } }