User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 402,623 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,174 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 2413 | Replies: 14
Reply
Join Date: Jun 2004
Location: H4x0rville
Posts: 2,105
Reputation: server_crash is on a distinguished road 
Rep Power: 9
Solved Threads: 18
server_crash's Avatar
server_crash server_crash is offline Offline
Postaholic

Re: need help asap :)

  #11  
Oct 14th, 2005
Originally Posted by riabear123
i had the limit variable up because i was going to have a counter, my teacher really cant teach and i dont know what the simple version is, i was to compare the numbers using a switch statement and then add the matches

As much help as he's given you, you should be able to FULLY understand. I'm sorry, but you're just interested in having the program written for you.
Reply With Quote  
Join Date: Jun 2005
Posts: 142
Reputation: G-Do is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 11
G-Do's Avatar
G-Do G-Do is offline Offline
Junior Poster

Re: need help asap :)

  #12  
Oct 14th, 2005
Hi riabear123,

The "simple version" is the game I described upthread, where you and I are drawing numbers out of a hat, with you winning pennies every time you get a match. I really wouldn't worry about the logic behind the payoff system until you have completed this simpler problem.

However, in the interest of completeness, let me give you my take on what the assignment specification is asking:

The lottery rules are like this. You pick 6 numbers, hoping to guess the numbers that will be drawn. When the drawing happens, there are 5 numbers drawn randomly between 1 and 49 inclusive, and then one more drawn from 1-42. The first 5 are unordered, but the last one is special and has to be an exact match to the last choice. Here is a table showing how much money you get for various numbers of matches between your picks and the numbers drawn.

Match Payoff

5/1 Jackpot, let's say it's$35M
5/0 $100K
4/1 $5K
4/0 $100
3/1 $100
3/0 $7
2/1 $7
2/0 $4
1/1 $4
1/0 $1
0/1 $1
So, you have six numbers and the Random object is used to create six random numbers. The rules are:

1) Look at the first five of your own numbers. Count how many of those five numbers match against any of the six random numbers. Create a variable called x which is equal to this count.

2) Look at the last of your numbers. Does it match the sixth random number? Create a variable called y which is 1 if there is a match and 0 if there is not.

Now, x and y can be used to figure out your payoff. Go to the line in that table above which starts with "x/y." That line has your payoff.

Let's do an example to see how this works. Suppose that our numbers are 4, 8, 15, 16, 23, and 42. Suppose that the current lottery (random) numbers are 8, 1, 13, 2, 34, and 21. In this case, x will be 1 (because only one of the first five lucky numbers, 8, appears in both lists). And since the last numbers don't match, y will be 0. So we go to line 1/0 and see that our payoff is $1 - not much. Now, suppose that we keep the same lucky numbers and get lottery (random) numbers of 22, 15, 41, 8, 16, and 42. In this case, x will be 3 (because three of the first five lucky numbers, 15, 8, and 16, appear in both lists). And since the last numbers match, y will be 1. So we go to line 3/1 and see that our payoff is a whopping $100!

Is this clear? It's not that you're comparing the 2nd lucky number to the 2nd random number - you're comparing to all the random numbers, and you're supposed to do this for each of the first five lucky numbers.

I hope this exchange has helped. Truthfully, I would like to help you more, but I have a fair amount of work to do, myself. Try to code the simple version of the program - you'll get different amounts of pennies each time, but on average (given 5 strips of paper and 1,000,000 tries) you should get about 200,000 of them per execution of the program.
Vi veri veniversum vivus vici
Reply With Quote  
Join Date: Oct 2005
Posts: 9
Reputation: riabear123 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
riabear123 riabear123 is offline Offline
Newbie Poster

Re: need help asap :)

  #13  
Oct 15th, 2005
Thank You
Reply With Quote  
Join Date: Oct 2005
Posts: 9
Reputation: riabear123 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
riabear123 riabear123 is offline Offline
Newbie Poster

Re: need help asap :)

  #14  
Oct 15th, 2005
I attachted my program so far to this message. My questions are how do I make the y's and X that equal one to add up so I can figure out my winnings

import java.util.Random;
class Lotto
{
public static void main (String[] args)
{
Random r = new Random();
int mynums[] = {6, 11, 15, 36, 37, 40};
int x=0;
int y=0;
int lotto[]= {r.nextInt(49)+1, r.nextInt(49)+1, r.nextInt(49)+1, r.nextInt(49)+1, r.nextInt(49)+1, r.nextInt(42)+1};

System.out.println("I have spent $1,000,000 on lottery tickets ");

{
if (y==1)
{
++y;
}
else
{
if(y==0)
{
y=y+0;
}
}
{





if (lotto[0]==mynums[1])
{
y=1;
}
else
{
if(lotto[0]!=mynums[1])
{
y=0;
}
}
if (lotto[0]==mynums[2])
{
y=1;
}
else
{
if(lotto[0]!=mynums[2])
{
y=0;
}
}
if (lotto[0]==mynums[3])
{
y=1;
}
else
{
if(lotto[0]!=mynums[3])
{
y=0;
}
}
if (lotto[0]==mynums[4])
{
y=1;
}
else
{
if(lotto[0]!=mynums[4])
{
y=0;
}
}

if (lotto[1]==mynums[0])
{
y=1;
}
else
{
if(lotto[1]!=mynums[0])
{
y=0;
}
}
if (lotto[1]==mynums[1])
{
y=1;
}
else
{
if(lotto[1]!=mynums[1])
{
y=0;
}
}
if (lotto[1]==mynums[2])
{
y=1;
}
else
{
if(lotto[1]!=mynums[2])
{
y=0;
}
}
if (lotto[1]==mynums[3])
{
y=1;
}
else
{
if(lotto[1]!=mynums[3])
{
y=0;
}
}
if (lotto[1]==mynums[4])
{
y=1;
}
else
{
if(lotto[1]!=mynums[4])
{
y=0;
}
}
if (lotto[2]==mynums[0])
{
y=1;
}
else
{
if(lotto[2]!=mynums[0])
{
y=0;
}
}
if (lotto[2]==mynums[1])
{
y=1;
}
else
{
if(lotto[2]!=mynums[1])
{
y=0;
}
}
if (lotto[2]==mynums[2])
{
y=1;
}
else
{
if(lotto[2]!=mynums[2])
{
y=0;
}
}
if (lotto[2]==mynums[3])
{
y=1;
}
else
{
if(lotto[3]!=mynums[3])
{
y=0;
}
}
if (lotto[3]==mynums[4])
{
y=1;
}
else
{
if(lotto[3]!=mynums[4])
{
y=0;
}
}
if (lotto[4]==mynums[0])
{
y=1;
}
else
{
if(lotto[4]!=mynums[0])
{
y=0;
}
}
if (lotto[4]==mynums[1])
{
y=1;
}
else
{
if(lotto[4]!=mynums[1])
{
y=0;
}
}
if (lotto[4]==mynums[2])
{
y=1;
}
else
{
if(lotto[4]!=mynums[2])
{
y=0;
}
}
if (lotto[4]==mynums[3])
{
y=1;
}
else
{
if(lotto[4]!=mynums[3])
{
y=0;
}
}
if (lotto[4]==mynums[4])
{
y=1;
}
else
{
if(lotto[4]!=mynums[4])
{
y=0;
}
}

}
if (lotto[5]==mynums[5])
{
x=1;
}
else
{
if(lotto[5]!=mynums[5])
{
x=0;

}
}
}
}
}



But you can see it better by just looking at the attachment
Attached Files
File Type: java Lotto.java (2.9 KB, 1 views)
Reply With Quote  
Join Date: Oct 2005
Posts: 9
Reputation: riabear123 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
riabear123 riabear123 is offline Offline
Newbie Poster

Re: need help asap :)

  #15  
Oct 16th, 2005
I have the program done now and i know its supposed to print out correctly but I have a small error somewhere that makes it not function. Can someone please check this attatchment?
Attached Files
File Type: java Lotto.java (3.9 KB, 3 views)
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Java Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 1:24 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC