Results 1 to 8 of 8

Thread: Lottery game

  1. #1
    Festimd is offline Member
    Join Date
    Jun 2012
    Posts
    3
    Rep Power
    0

    Question Lottery game

    Write a program which simulates a lottery game (6 of 36).
    1. The application initially asks the user gives as input 6 numbers (there should be no repetition for numbers).
    2. The application will generate 6 random numbers in the range 1 to 36 (there should be no repeat of numbers).
    3. The application will compare the numbers of user input and generate numbers (from application) and will show the result (as has shot numbers of users)
    Additional information (help): During the development of power will have to use strings (arrays) and cilke (Loops).
    (Oblikative) A. Introduction of 6 numbers have to save in a range (int []). Selected numbers should not repeated! This should check during the process of selecting the numbers from the user with! 2. Store random numbers in a range (int []). To generate these numbers using the method Math.random (). Also, this process should you care that the application not generate numbers that are repeated! Documentation: Math (Java Platform SE 6) search method random (). 3. Analyzing the selected numbers and Numan generated, the application should display a message which shows how the numbers have shot occupant (x of 6)! Also encourage you to use as many classes / objects and methods (eg a method to check whether the numbers that are repeated), this is not mandatory, but will facilitate the process of programming!

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Lottery game

    Thank you very much for posting your assignment, and it looks like a good one. Please be assured that all of us here at the Java-Forums.org wish you well in working towards its completion. Oh, also, if you need help here, please feel free to ask a specific question, and show the current fruits of your efforts.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,529
    Blog Entries
    7
    Rep Power
    20

    Default Re: Lottery game

    Have a look at the Collections.shuffle( ... ) and Collection.sort( ... ) methods; they'll help you a lot.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    Default Re: Lottery game

    Quote Originally Posted by Festimd View Post
    Can you help me to whrite it in JAVA ?
    For our definition of help, yes. Post a SSCCE (Short, Self Contained, Correct (Compilable), Example) that shows where you're stuck.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Lottery game

    Quote Originally Posted by Festimd View Post
    Can you help me to whrite it in JAVA ?
    This question is just too broad for us to be able to give a specific answer, and about the best we can do for this is to point you to the Java tutorials where you can hopefully learn enough Java to be able to at last ask a better question. Understand please that no one is going to write this for you, nor should they, as they would be cheating you out of a valuable learning experience. Please first try to solve this on your own; take a look at this link which can help you: So, You Need to Write a Program but Don't Know How to Start, and then please come back if you have any specific answerable questions.

  6. #6
    Festimd is offline Member
    Join Date
    Jun 2012
    Posts
    3
    Rep Power
    0

    Question Re: Lottery game

    I need it for a short period of time that's why i asked for help.Please forgive me for the unpolite way of question, here is my work but i can't totally adjust it to the program request can u tell me what to change in my code? thanks a lot for the time you dedicated to me.

    public class Lottery {
    public static void main(String[]args) {
    int setCount = 1; // Number of sets of lucky numbers.
    int setSize = 6; // Number of lucky numbers in the set.
    int range = 36; // Assume selecting integers between 1 and range.
    int lucky; // Holds a lucky number candidate.
    int luckyCount; // Holds count of lucky numbers in a set.

    for(int i = 0 ; i < setCount ; ++i) {
    JOptionPane.showInputDialog("Shkruaj numrin e pare :" );
    JOptionPane.showInputDialog("Shkruaj numrin e dyte :" );
    JOptionPane.showInputDialog("Shkruaj numrin e trete :" );
    JOptionPane.showInputDialog("Shkruaj numrin e katert :" );
    JOptionPane.showInputDialog("Shkruaj numrin e peste :" );
    JOptionPane.showInputDialog("Shkruaj numrin e gjashte :" );
    int lucky1 = 0; // Lucky numbers for the set of 6.
    int lucky2 = 0;
    int lucky3 = 0;
    int lucky4 = 0;
    int lucky5 = 0;
    int lucky6 = 0;

    luckyCount = 0; // Count of numbers found in the current set
    while(luckyCount < setSize) {
    // Generate a lucky number between 0 and 48 and add 1:
    lucky = (int)(range*Math.random()) + 1;
    switch(luckyCount) {
    case 0: // It is the first one
    lucky1 = lucky; // so just store it
    luckyCount++; // and increment the count
    break;
    case 1: // For the second we must
    if(lucky != lucky1) { // check that it is different from the first
    lucky2 = lucky; // It is, so store it
    luckyCount++; // and increment the count
    }
    break;
    case 2: // For the third we check aginst the previous two
    if(lucky != lucky1 && lucky != lucky2) {
    lucky3 = lucky;
    luckyCount++;
    }
    break;
    case 3: // Check against the previous three...
    if(lucky != lucky1 && lucky != lucky2 && lucky != lucky3) {
    lucky4 = lucky;
    luckyCount++;
    }
    break;
    case 4: // Check against the previous four...
    if(lucky != lucky1 && lucky != lucky2 && lucky != lucky3 && lucky != lucky4) {
    lucky5 = lucky;
    luckyCount++;
    }
    break;
    case 5: // Check against the previous five...
    if(lucky != lucky1 && lucky != lucky2 && lucky != lucky3 && lucky != lucky4 && lucky != lucky5) {
    lucky6 = lucky;
    luckyCount++;
    }
    break;
    }
    }

    System.out.print("\nSet " + (i + 1) + ":"); // Identify the set

    JOptionPane.showMessageDialog(null," " + lucky1 + " " + lucky2 + " " + lucky3 + // and output the numbers
    " " + lucky4 + " " + lucky5 + " " + lucky6);

    }
    }
    }

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,529
    Blog Entries
    7
    Rep Power
    20

    Default Re: Lottery game

    Again, have a look at the Collections.shuffle( ... ) method; it gets rid of those tedious tests.

    kind regarrds,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    Festimd is offline Member
    Join Date
    Jun 2012
    Posts
    3
    Rep Power
    0

Similar Threads

  1. Lottery Application
    By leoshiner in forum New To Java
    Replies: 2
    Last Post: 03-06-2012, 01:02 PM
  2. Lottery Java Program please help
    By grcarr77 in forum New To Java
    Replies: 1
    Last Post: 10-16-2011, 07:20 PM
  3. Random Lottery Numbers
    By ComicStix in forum New To Java
    Replies: 2
    Last Post: 04-29-2011, 06:18 AM
  4. lottery
    By kayln in forum Eclipse
    Replies: 0
    Last Post: 02-20-2011, 09:28 PM
  5. Lottery Application
    By notnumber6 in forum New To Java
    Replies: 3
    Last Post: 11-03-2007, 11:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •