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.


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

Results 1 to 3 of 3

Thread: im i on the righ tracks

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

    Exclamation im i on the righ tracks

    for our coursework we had to make a lottery random number ticket generator

    The 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).

    The Ticket class should provide the following functionality:
     Construct a Lottery Ticket that allows the customer to have as many randomly generated Lucky Dips as they require on the same ticket.
     Store the ‘Lucky Dip’ number sets in a flexible-sized collection (array list).
     Display the ticket and ‘Lucky Dip’ numbers to the screen in the correct format.

    i have started with the numbers class and my question is that im i on the right path also can anyone guide me because somewhere i need a loop

    //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 value 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);
    //Print out the line of numbers.
    System.out.println(Lotto[0] + ", " + Lotto[1] + ", " + Lotto[2] + ", " + Lotto[3] + ", " + Lotto[4] + ", " + Lotto[5]);

  2. #2
    Member vigneshwaran's Avatar
    Join Date
    Nov 2012
    Chennai, TamilNadu
    My Mood
    Thanked 1 Time in 1 Post

    Default Re: im i on the righ tracks

    where is the main method?
    to print the values of an array Lotto[],
    for(int i=0;i<MAX;i++)

    i guess the variable int qty on the line
    public void generateNums(int qty) {...}
    was not used

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Eastern Florida
    Thanked 2,475 Times in 2,426 Posts

    Default Re: im i on the righ tracks

    Please edit your post and wrap your code with
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.