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 6 of 6

Thread: putting comments in for code

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default putting comments in for code

    hi a while back I started to put comments on the code and now I have lost some of them, could anyone help me comment this unfinshed peice of code

    //access to the java.utill.random libary.
        import java.util.Random;
    /**
     * Lucky dip lottery ticket system.
     * @author Daniel Prempeh
     * @version 1.1 2013
     */
     
    public class Numbers
        {
        private int[] Lotto;
        private final int MAX=6;
     
    public Numbers()
        {   
            Lotto = new int[MAX];
        }
     
    public void generateNums(int qty)
        {
            //assign random values to 6 lines of intergers.
            Lotto[0] = 1 + (int) (Math.random() * 49);
            Lotto[1] = 1 + (int) (Math.random() * 49);
            Lotto[2] = 1 + (int) (Math.random() * 49);
            Lotto[3] = 1 + (int) (Math.random() * 49);
            Lotto[4] = 1 + (int) (Math.random() * 49);
            Lotto[5] = 1 + (int) (Math.random() * 49);
            for(int i=0;i<MAX;i++)
        {   
            //to print the values of an array
            System.out.println(Lotto[i]);
        }
        }
        }
    Last edited by helloworld922; January 7th, 2013 at 07:28 PM. Reason: please use [code] tags


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: putting comments in for code

    help me comment this unfinshed peice of code
    The comments in a piece of code should come from the design for the code.
    If you have defined what the code should do, add the thoughts that describe that design as comments to the code.

    How can anyone comment unfinished code? The comments should reflect what the code does.

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: putting comments in for code

    my tutor was like you should start to be able to comment on your code and I did when I started this but I have lost some of it

    basically it is a Numbers class should provide the following functionality:
     Generates 6 random numbers in a range 1 to 49.
     Write YOUR OWN custom method incorporating an algorithm to sort the numbers in ascending order.
     Store the 6 numbers in a fixed-sized collection (array).
     Format and display the numbers (number output in the range 1 to 9 should be preceded by a blank space).

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: putting comments in for code

    Sorry, why can't you add the comments in your last post to the code?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Dec 2012
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: putting comments in for code

    I commented the code but lost it a long time ago and now forgot what comments to put in the code now

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: putting comments in for code

    Comments should say what the code does. If you wrote the code, do you know what you wanted the code to do and how the code was going to do that?

    If you didn't write the code, then maybe you should start over: make a design for the program, make a list of the steps the code should do, add that list of steps to the code as you write it.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 1
    Last Post: October 22nd, 2012, 07:19 PM
  2. Help With Putting This Math Problem Into Code
    By Pettsa in forum Object Oriented Programming
    Replies: 23
    Last Post: May 28th, 2012, 06:48 PM
  3. Comments or Suggestions on Some Code
    By mike_p in forum Object Oriented Programming
    Replies: 2
    Last Post: March 8th, 2012, 05:51 PM
  4. Comments
    By igkarthi in forum Java Theory & Questions
    Replies: 1
    Last Post: January 27th, 2012, 07:52 AM