Results 1 to 8 of 8
Thread: Lottery game
- 06-05-2012, 08:00 PM #1
Member
- Join Date
- Jun 2012
- Posts
- 3
- Rep Power
- 0
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!
-
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.
- 06-05-2012, 08:03 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,427
- Blog Entries
- 7
- Rep Power
- 17
Re: Lottery game
Have a look at the Collections.shuffle( ... ) and Collection.sort( ... ) methods; they'll help you a lot.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 06-05-2012, 08:23 PM #4
Re: Lottery game
For our definition of help, yes. Post a SSCCE (Short, Self Contained, Correct (Compilable), Example) that shows where you're stuck.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
-
Re: Lottery game
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.
- 06-06-2012, 09:59 PM #6
Member
- Join Date
- Jun 2012
- Posts
- 3
- Rep Power
- 0
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);
}
}
}
- 06-06-2012, 10:04 PM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,427
- Blog Entries
- 7
- Rep Power
- 17
Re: Lottery game
Again, have a look at the Collections.shuffle( ... ) method; it gets rid of those tedious tests.
kind regarrds,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 06-06-2012, 10:08 PM #8
Member
- Join Date
- Jun 2012
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
Lottery Application
By leoshiner in forum New To JavaReplies: 2Last Post: 03-06-2012, 01:02 PM -
Lottery Java Program please help
By grcarr77 in forum New To JavaReplies: 1Last Post: 10-16-2011, 07:20 PM -
Random Lottery Numbers
By ComicStix in forum New To JavaReplies: 2Last Post: 04-29-2011, 06:18 AM -
lottery
By kayln in forum EclipseReplies: 0Last Post: 02-20-2011, 09:28 PM -
Lottery Application
By notnumber6 in forum New To JavaReplies: 3Last Post: 11-03-2007, 11:42 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks