Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Comments In Java

  1. #1
    Junior Member
    Join Date
    Dec 2013
    Posts
    9
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Comments In Java

    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;
    	}								
    }
    Last edited by Flying216; February 2nd, 2014 at 07:12 AM. Reason: Highlighting buf


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,472
    My Mood
    Mellow
    Thanks
    151
    Thanked 609 Times in 596 Posts

    Default Re: Comments In Java

    Are those comments even working for you? Aren't you seeing errors. Fix the incorrect multi-line comment and repost.

  3. #3
    Junior Member
    Join Date
    Dec 2013
    Posts
    9
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Comments In Java

    Oh shoot, on my screen it all lines up perfectly, but I did notice on my tablet the weird malfunction. It is because I use a television for coding. Even on the lowest resolution my notepad opens up like 40 lines down and like 180 characters across. I will readjust it.

    Edit: Finished adjusting the new post, the screen is still buggy on my tablet because it doesn't accept the java highlight code appropriately(It won't let it scroll right)

Similar Threads

  1. Java Comments Quality - Academic Survey - $10
    By mcmillco in forum Paid Java Projects
    Replies: 1
    Last Post: June 9th, 2013, 08:15 PM
  2. How do you feel about my javadoc comments?
    By bdennin in forum Java Theory & Questions
    Replies: 1
    Last Post: January 31st, 2013, 07:38 PM
  3. Comments
    By igkarthi in forum Java Theory & Questions
    Replies: 1
    Last Post: January 27th, 2012, 06:52 AM