I need my lottery program to count the number of times 0,1,2,3,4 or 5 numbers match after 10 runs, then display them. It is also supposed to keep track of the total jackpot by adding a certain amount to the jackpot depending on how many numbers won. My problem is that is is counting this correctly for each individual run but not for all ten runs total. here is what I have.
package assignment5;
import javax.swing.JOptionPane;
import java.util.Random;
public class assignment5
{
public static void main(String[] args)
{
for(int i = 0; i <10; i++)
{
lottery pic=new lottery();
pic.Get_player_numbers();
pic.Get_jackpot_number();
pic.Check_winner ();
pic.Write_data();
}}
}
class lottery
{
int[] picks= new int[5];
int[] cpick=new int[5];
int i;
int j,c;
int match=0;
void Get_player_numbers ()
{
int ctemp,cdupflag=0;
for(j=0;j<=4;++j)
{
//YOU DO NOT NEED THE CNUMBERFLAG
//IF YOU GENERATED THE NUMBERS CORRECLTY, THE COMPUTER WILL NOT GENERATE ONE ABOVE 99 OR LESS THAN 1
cdupflag=0;
while(cdupflag==0)
{
ctemp = (int)Math.round(Math.random()*99)+1;
cdupflag=1;
for(c=0;c<=j;++c)
{
if(ctemp==cpick[c])
{
cdupflag=0;
}
}//inner for loop
if(cdupflag==1)
cpick[j]=ctemp;
}
}
String Jackpot="User Lottery numbers are: "+"\n";
//String computer = "";
for(j=0;j<=4;++j)
{
if(j==4)
Jackpot=Jackpot+cpick[j];
else
Jackpot=Jackpot+cpick[j]+"-";
}
JOptionPane.showMessageDialog(null,Jackpot,"Output:",JOptionPane.INFORMATION_MESSAGE);
}
//void jackpot()
void Get_jackpot_number()
{
int ctemp,cdupflag=0;
for(j=0;j<=4;++j)
{
//YOU DO NOT NEED THE CNUMBERFLAG
//IF YOU GENERATED THE NUMBERS CORRECLTY, THE COMPUTER WILL NOT GENERATE ONE ABOVE 99 OR LESS THAN 1
cdupflag=0;
while(cdupflag==0)
{
ctemp = (int)Math.round(Math.random()*99)+1;
cdupflag=1;
for(c=0;c<=j;++c)
{
if(ctemp==cpick[c])
{
cdupflag=0;
}
}//inner for loop
if(cdupflag==1)
cpick[j]=ctemp;
}
}
String Jackpot="Computer Lottery numbers are: "+"\n";
//String computer = "";
for(j=0;j<=4;++j)
{
if(j==4)
Jackpot=Jackpot+cpick[j];
else
Jackpot=Jackpot+cpick[j]+"-";
}
JOptionPane.showMessageDialog(null,Jackpot,"Output:",JOptionPane.INFORMATION_MESSAGE);
}
void Check_winner ()
{
for(int i=0;i<=4;++i)
{
for(int j=0;j<=4;++j)
{
if(picks[i]==cpick[j])
{
match=match+1;
}
}
}
}
void Write_data ()
{
String print = "";
int jackpot = 2500000;
int counter0 = 0;
int counter1 = 0;
int counter2 = 0;
int counter3 = 0;
int counter4 = 0;
int counter5 = 0;
if(match==0)
{
counter0++;
print=print+"There is no match"+"\n";
print=print+"please try again "+"\n";
jackpot=jackpot+25000;
}
else
if(match==1)
{
counter1++;
print=print+"There is one match"+"\n";
print=print+"You won 100 Dollars "+"\n";
jackpot=jackpot+100000;
}
else
if(match==2)
{
counter2++;
print=print+"There are two matches"+"\n";
print=print+"You won 1,000 Dollars"+"\n";
jackpot=jackpot+250000;
}
else
if(match==3)
{
counter3++;
print=print+"There are three matches"+"\n";
print=print+"You won 10,000 Dollars "+"\n";
jackpot=jackpot+500000;
}
else
if(match==4)
{
counter4++;
print=print+"There are four matches"+"\n";
print=print+"You won 100,000 Dollars "+"\n";
jackpot=jackpot+1000000;
}
else
if(match==5)
{
counter5++;
print=print+"There are five matches"+"\n";
print=print+"You won "+jackpot+" Dollars"+"\n";
jackpot=2500000;
}
JOptionPane.showMessageDialog(null,print,"Output:",JOptionPane.INFORMATION_MESSAGE);
System.out.println("zero matchers occured " +counter0+ " times");
System.out.println("The current jackpot is " +jackpot+ "");
}
}
//end of class lottery
Aucun commentaire:
Enregistrer un commentaire