6 Replies - 11726 Views - Last Post: 04 February 2012 - 08:40 PM Rate Topic: -----

#1 hellochase14   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 04-February 12

Java Lottery Program Help

Posted 04 February 2012 - 02:12 PM

I have an assignment that is supposed to run a max of 20 times, the user is supposed to pick five numbers between 1-99 and then the computer will generate five numbers too and will report in any of the numbers will match. The jackpot starts at 2,500,000 and then each number that hits has a payout. However if 1-4 numbers were to hit you are supposed to add in money to the starting jackpot. I was not sure how to do this and how to show an output of the current jackpot, player numbers, winning numbers, how many matched and payout,

Here is my code so far:

import java.util.Scanner;
	import java.util.Random;
	 
	 
	public class Lottery1 {
	 
	    private int[] lucky = new int[5];
	    private int jackpot = 0;
	    private Scanner sc = new Scanner(System.in);
	    private Random r1 = new Random();
	    private Random r2 = new Random();
	    private Random r3 = new Random();
	    private Random r4 = new Random();
	    private Random r5 = new Random();
	 
	    private int num1 = r1.nextInt(99);
	    private int num2 = r2.nextInt(99);
	    private int num3 = r3.nextInt(99);
	    private int num4 = r4.nextInt(99);
	    private int num5 = r5.nextInt(99);
	    private int i;
	 
	     
	 
	    public Lottery1(){
	    System.out.println("Jackpot starts at $2,500,000. No matches equals $25,000 added to jackpot." +
	    		"One number that matches, the payout is $1,000 and $100,000 is added to the jackpot." +
	    		"Two numbers that match, the payout is $10,000 and $250,000 is added to the jackpot." +
	    		"Three numbers that match, the payout is $100,000and $500,000 is added to the jackpot." +
	    		"Four numbers that match, the payout is $500,000 and $1,000,000 is added to the jackpot");
	             
	            System.out.println();
	            numbers();
	            pick(lucky);
	             
	         
	        System.out.println("////////////////////////");
	        System.out.println("The wining numbers are");
	        System.out.println(num1);
	        System.out.println(num2);
	        System.out.println(num3);
	        System.out.println(num4);
	        System.out.println(num5);
	        System.out.println("////////////////////////");
	        System.out.println("You Won $"+jackpot);
	         
	         
	    }
	     
	    public static void main (String args[]){
	        Lottery1 lottery = new Lottery1();
	         
	    }
	     
	    public void pick(int[]lucky){
	             
	        if(lucky[0]==num1 && lucky[1]==num2 && lucky[2]==num3 && lucky[3]==num4 && lucky[4]==num5) {
	            jackpot=2500000;
	            return;
	        }
	 
	         
	         
	    for (int i=0;i<lucky.length;i++){
	    	
	    	if(( lucky[i]==num1|| lucky[i]==num2 || lucky[i]==num3 || lucky[i]==num4 || lucky[i]==num5))
	              jackpot=1000;
	              
	    	
	    	
	        if( ((lucky[i]==num1)&&(lucky[i]==num2))||
	        	((lucky[i]==num1)&&(lucky[i]==num3))||
	        	((lucky[i]==num1)&&(lucky[i]==num4))||
	        	((lucky[i]==num1)&&(lucky[i]==num5))||
	            ((lucky[i]==num2)&&(lucky[i]==num3))||
	            ((lucky[i]==num2)&&(lucky[i]==num4))||
	            ((lucky[i]==num2)&&(lucky[i]==num5))||
	            ((lucky[i]==num3)&&(lucky[i]==num4))||
	            ((lucky[i]==num3)&&(lucky[i]==num5))||
	            ((lucky[i]==num4)&&(lucky[i]==num5))){
	                jackpot = 10000;
	                
	                

	                if( ((lucky[i]==num1)&&(lucky[i]==num2)&&(lucky[i]==num3))||
	    	        	((lucky[i]==num1)&&(lucky[i]==num2)&&(lucky[i]==num4))||
	    	        	((lucky[i]==num1)&&(lucky[i]==num2)&&(lucky[i]==num5))||
	    	        	((lucky[i]==num1)&&(lucky[i]==num3)&&(lucky[i]==num4))||
	    	        	((lucky[i]==num1)&&(lucky[i]==num3)&&(lucky[i]==num5))||
	    	        	((lucky[i]==num1)&&(lucky[i]==num4)&&(lucky[i]==num5))||
	    	            ((lucky[i]==num2)&&(lucky[i]==num3)&&(lucky[i]==num4))||
	    	            ((lucky[i]==num2)&&(lucky[i]==num3)&&(lucky[i]==num5))||
	    	            ((lucky[i]==num2)&&(lucky[i]==num4)&&(lucky[i]==num5))||
	    	            ((lucky[i]==num3)&&(lucky[i]==num4)&&(lucky[i]==num5))){
	    	                jackpot = 100000;
	                
	                
	    	                if(
	    		    	        	((lucky[i]==num1)&&(lucky[i]==num2)&&(lucky[i]==num3)&&(lucky[i]==num4))||
	    		    	        	((lucky[i]==num1)&&(lucky[i]==num2)&&(lucky[i]==num3)&&(lucky[i]==num5))||
	    		    	        	((lucky[i]==num1)&&(lucky[i]==num3)&&(lucky[i]==num4)&&(lucky[i]==num3))||
	    		    	        	((lucky[i]==num1)&&(lucky[i]==num3)&&(lucky[i]==num4)&&(lucky[i]==num5))||
	    		    	        	((lucky[i]==num1)&&(lucky[i]==num4)&&(lucky[i]==num5)&&(lucky[i]==num3))||
	    		    	            ((lucky[i]==num2)&&(lucky[i]==num3)&&(lucky[i]==num4)&&(lucky[i]==num5))){           
	    		    	                jackpot = 500000;
	                return;
	            }
	             
	          
	                 
	            }
	    }
	       
	         
	
	    public void numbers(){
	    System.out.println("First nummber");         
	      i = sc.nextInt();
	     lucky[0] = i%99;
	      
	     System.out.println("Second nummber");       
	      i = sc.nextInt();
	     lucky[1] = i%99;
	     
	     System.out.println("Third number");       
	      i = sc.nextInt();
	     lucky[2] = i%99;
	     
	     System.out.println("Fourth number");       
	      i = sc.nextInt();
	     lucky[3] = i%99;
	     
	     System.out.println("Fifth nummber");       
	      i = sc.nextInt();
	     lucky[4] = i%99;
	    }
	}
	    


Is This A Good Question/Topic? 0
  • +

Replies To: Java Lottery Program Help

#2 macosxnerd101   User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12314
  • View blog
  • Posts: 45,411
  • Joined: 27-December 08

Re: Java Lottery Program Help

Posted 04 February 2012 - 02:26 PM

You should still store your lucky numbers in an array. It makes it much easier to compare the picks with the generated numbers. Also, you only need one Random object, not 5.

Since jackpot is an instance field, reference this.jackpot += additionalMoney;, where additionalMoney is the amount of money to add to the jackpot.

Quote

how to show an output of the current jackpot, player numbers, winning numbers, how many matched and payout,

You can use System.out.println() to output the values.
Was This Post Helpful? 0
  • +
  • -

#3 hellochase14   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 04-February 12

Re: Java Lottery Program Help

Posted 04 February 2012 - 02:42 PM

I am not sure exactly what you mean, this is my second java assignment for my class, and I am not fully understanding.
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101   User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12314
  • View blog
  • Posts: 45,411
  • Joined: 27-December 08

Re: Java Lottery Program Help

Posted 04 February 2012 - 02:44 PM

What specifically do you need me to clarify?
Was This Post Helpful? 0
  • +
  • -

#5 hellochase14   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 04-February 12

Re: Java Lottery Program Help

Posted 04 February 2012 - 02:55 PM

If the user only got 1 number right $1000 would be the payout and the jackpot would get $100,000 added to it. How would I get the $100,000 into the jackpot sum?
Was This Post Helpful? 0
  • +
  • -

#6 macosxnerd101   User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12314
  • View blog
  • Posts: 45,411
  • Joined: 27-December 08

Re: Java Lottery Program Help

Posted 04 February 2012 - 07:45 PM

Use the sample I provided above. You literally assign this.jackpot += 100000;.
Was This Post Helpful? 0
  • +
  • -

#7 hellochase14   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 04-February 12

Re: Java Lottery Program Help

Posted 04 February 2012 - 08:40 PM

Here is the code I have so far, I am not sure if the payout adding is going in right and I am not sure how to get game to run a total of 20 times:

import java.util.Scanner;
	import java.util.Random;
	 
	 
	public class Lottery1 {
	 
		
		private int payout = 0;
	    private int[] lucky = new int[5];
	    private int jackpot = 2500000;
	    private Scanner sc = new Scanner(System.in);
	    private Random r1 = new Random();
	    private Random r2 = new Random();
	    private Random r3 = new Random();
	    private Random r4 = new Random();
	    private Random r5 = new Random();
	 
	    private int num1 = r1.nextInt(99);
	    private int num2 = r2.nextInt(99);
	    private int num3 = r3.nextInt(99);
	    private int num4 = r4.nextInt(99);
	    private int num5 = r5.nextInt(99);
	    private int i;
	 
	    
	
	 
	    public Lottery1(){
	    System.out.println("Jackpot starts at $2,500,000. No matches equals $25,000 added to jackpot." +
	    		"One number that matches, the payout is $1,000 and $100,000 is added to the jackpot." +
	    		"Two numbers that match, the payout is $10,000 and $250,000 is added to the jackpot." +
	    		"Three numbers that match, the payout is $100,000and $500,000 is added to the jackpot." +
	    		"Four numbers that match, the payout is $500,000 and $1,000,000 is added to the jackpot");
	             
	            System.out.println();
	            numbers();
	            pick(lucky);
	             
	         
	        System.out.println("////////////////////////");
	        System.out.println("The wining numbers are");
	        System.out.println(num1);
	        System.out.println(num2);
	        System.out.println(num3);
	        System.out.println(num4);
	        System.out.println(num5);
	        System.out.println("////////////////////////");
	        System.out.println("Payout $"+payout);
	        System.out.println("Current Jackpot $"+jackpot);
	    }
	     
	    public static void main (String args[]){
	        Lottery1 lottery1 = new Lottery1();
	      
	    }
	     
	    public void pick(int[]lucky){
	    	    
	           payout = 0;
	           jackpot = 2500000;
	    	   
	    	   if(lucky[0]==num1 && lucky[1]==num2 && lucky[2]==num3 && lucky[3]==num4 && lucky[4]==num5) {
	           
	            
	            payout = payout +2500000;
	            return;
	        }
	 
	         
	         
	    for (int i=0;i<lucky.length;i++){
	    	
                 
                  
                  if( ((lucky[i]==num1))||
                      ((lucky[i]==num2))||
                      ((lucky[i]==num3))||
                      ((lucky[i]==num4))||
                      ((lucky[i]==num5)));
                     
                      payout = payout + 0;
                      jackpot = jackpot + 25000;
                		  
	              
	    	
	    	
	        if( ((lucky[i]==num1)&&(lucky[i]==num2))||
	        	((lucky[i]==num1)&&(lucky[i]==num3))||
	        	((lucky[i]==num1)&&(lucky[i]==num4))||
	        	((lucky[i]==num1)&&(lucky[i]==num5))||
	            ((lucky[i]==num2)&&(lucky[i]==num3))||
	            ((lucky[i]==num2)&&(lucky[i]==num4))||
	            ((lucky[i]==num2)&&(lucky[i]==num5))||
	            ((lucky[i]==num3)&&(lucky[i]==num4))||
	            ((lucky[i]==num3)&&(lucky[i]==num5))||
	            ((lucky[i]==num4)&&(lucky[i]==num5))){
	               
	                
	                payout = payout + 10000;
	                jackpot = jackpot + 250000;
		            
	                
	                

	                if( ((lucky[i]==num1)&&(lucky[i]==num2)&&(lucky[i]==num3))||
	    	        	((lucky[i]==num1)&&(lucky[i]==num2)&&(lucky[i]==num4))||
	    	        	((lucky[i]==num1)&&(lucky[i]==num2)&&(lucky[i]==num5))||
	    	        	((lucky[i]==num1)&&(lucky[i]==num3)&&(lucky[i]==num4))||
	    	        	((lucky[i]==num1)&&(lucky[i]==num3)&&(lucky[i]==num5))||
	    	        	((lucky[i]==num1)&&(lucky[i]==num4)&&(lucky[i]==num5))||
	    	            ((lucky[i]==num2)&&(lucky[i]==num3)&&(lucky[i]==num4))||
	    	            ((lucky[i]==num2)&&(lucky[i]==num3)&&(lucky[i]==num5))||
	    	            ((lucky[i]==num2)&&(lucky[i]==num4)&&(lucky[i]==num5))||
	    	            ((lucky[i]==num3)&&(lucky[i]==num4)&&(lucky[i]==num5))){
	    	               
	    	                
	    		            payout = payout + 100000;
	    		            jackpot = jackpot + 500000;
	                
	                
	    	                if(
	    		    	        	((lucky[i]==num1)&&(lucky[i]==num2)&&(lucky[i]==num3)&&(lucky[i]==num4))||
	    		    	        	((lucky[i]==num1)&&(lucky[i]==num2)&&(lucky[i]==num3)&&(lucky[i]==num5))||
	    		    	        	((lucky[i]==num1)&&(lucky[i]==num3)&&(lucky[i]==num4)&&(lucky[i]==num3))||
	    		    	        	((lucky[i]==num1)&&(lucky[i]==num3)&&(lucky[i]==num4)&&(lucky[i]==num5))||
	    		    	        	((lucky[i]==num1)&&(lucky[i]==num4)&&(lucky[i]==num5)&&(lucky[i]==num3))||
	    		    	            ((lucky[i]==num2)&&(lucky[i]==num3)&&(lucky[i]==num4)&&(lucky[i]==num5))){           
	    		    	               
	    		    	                
	    		    	                payout = payout + 500000;
	    		    	                jackpot = jackpot +1000000;
	                return;
	            }
	             
	          
	                 
	            }
	    }
	    }
	    }
	         
	
	    public void numbers(){
	    System.out.println("First nummber");         
	      i = sc.nextInt();
	     lucky[0] = i%99;
	      
	     System.out.println("Second nummber");       
	      i = sc.nextInt();
	     lucky[1] = i%99;
	     
	     System.out.println("Third number");       
	      i = sc.nextInt();
	     lucky[2] = i%99;
	     
	     System.out.println("Fourth number");       
	      i = sc.nextInt();
	     lucky[3] = i%99;
	     
	     System.out.println("Fifth nummber");       
	      i = sc.nextInt();
	     lucky[4] = i%99;
	    }
	}
	     

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1