2 Replies - 8168 Views - Last Post: 09 November 2009 - 08:24 PM Rate Topic: -----

#1 pinkdreammss  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 09-November 09

Lottery game in java

Post icon  Posted 09 November 2009 - 12:18 AM

hey guys .
im new with this forum and Java programming .
im gonna code a lottery simulator in JAVA . as you can see in below i got some problem in coding that cause my program wont compile .
would you take a look at it and help me to develop this application ...
by the way ive checked other created topic regarding to this Lottery game , however non of them were using my way , using array.
"
i want the user enter 3 digits so program will compare the entered digits with random numbers from 1 to 10 , if one of the entered numbers match with random digits , display user wins 10$ , if 2 number match , user wins 100$, if all of them match , user wins 100000$ ! "



import java.util.Scanner;
import java.util.Random;
public class Lottery {
public static void main (String args[]){
int lucky=new int[3];
int bingo=0;
	
Random r1=new Random();
Random r2=new Random();
Random r3=new Random();

int num1=r1.nextInt(10);
int num2=r2.nextInt(10);
int num3=r3.nextInt(10);
}

public static void pick(int[]lucky){
for (int i=0;i<lucky.length;i++){
System.out.print("enter 3 number ! ");
if (lucky[0]==num1 || lucky[0]==num2 || lucky[0]==num3)
{
bingo=bingo+10;}
	else if  {

	 (lucky[1]==num1 || lucky[1]==num2 || lucky[1]==num3)} else if  (bingo==10){bingo=bingo+90;}

else if (lucky[2]==num1 || lucky[2]==num2 || lucky[2]==num3)
	
						(else if bingo==100){bingo=bingo+900}
 
 	else if (lucky[]==num1||lucky[]==num2||lucky[]==num3)if (bingo=1000)

{ bingo==bingo+9000}
						else {bingo==0;}

}
}


Is This A Good Question/Topic? 0
  • +

Replies To: Lottery game in java

#2 DaneAU  Icon User is offline

  • Great::Southern::Land
  • member icon

Reputation: 286
  • View blog
  • Posts: 1,619
  • Joined: 15-May 08

Re: Lottery game in java

Posted 09 November 2009 - 12:59 AM

Well first thing you can do is format the code so you can see the if statements clearly, thats what i just did and i found numerous errors some examples include
else if {lucky[1]==num1 || lucky[1]==num2 || lucky[1]==num3)}

which should perhaps be else if ( lucky[1]==num1 || lucky[1]==num2 || lucky[1]==num3) { }

There are a large amount of errors, so best thing to do is to start again and focus on indenting your code especially for else-if statements
eg.
int x = 3;

if ( x < 0 )
{
   // do something
}
else if ( x < 10 )
{
   // do something
}

else if ( x < 50 )
{
    // do something
}
else
    // do something



edit **

This post has been edited by bbq: 09 November 2009 - 12:59 AM

Was This Post Helpful? 0
  • +
  • -

#4 chaos386  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 28
  • Joined: 27-February 09

Re: Lottery game in java

Posted 09 November 2009 - 08:24 PM

well bbq is real help full is'ent it lol any who your coded is a mess so i re typed it and fixed up the erreos and made it so your program can read in put from the screen flick me and IM if your still having problems


import java.util.Scanner;
import java.util.Random;


public class Lottery {

	private	int[] lucky = new int[3];
	private	int bingo = 0;
	private Scanner sc = new Scanner(System.in);
	private Random r1 = new Random();
	private Random r2 = new Random();
	private Random r3 = new Random();

	private int num1 = r1.nextInt(10);
	private int num2 = r2.nextInt(10);
	private int num3 = r3.nextInt(10);
	private int i;

	

	public Lottery(){
	System.out.println("Bingo $10000 for 3 numbers, $100 for 2 numbers and $10 for 1 number");
			
			System.out.println();
			numbers();
			pick(lucky);
			
		
		System.out.println("////////////////////////");
		System.out.println("The win'ing numbers are");
		System.out.println(num1);
		System.out.println(num2);
		System.out.println(num3);
		System.out.println("////////////////////////");
		System.out.println("You Won $"+bingo);
		
		
	}
	
	public static void main (String args[]){
		Lottery lottery = new Lottery();
		
	}
	
	public void pick(int[]lucky){
			
		if(lucky[0]==num1 && lucky[1]==num2 && lucky[2]==num3){
			bingo=100000;
			return;
		}

		
		
	for (int i=0;i<lucky.length;i++){
					
		if( ((lucky[i]==num1)&&(lucky[i]==num2))||
			((lucky[i]==num2)&&(lucky[i]==num3))||
			((lucky[i]==num3)&&(lucky[i]==num2))){
				bingo = 100;
				return;
			}
			
			if (lucky[i]==num1 || lucky[i]==num2 || lucky[i]==num3){
				bingo=10;
				
			}
	}
		return;
		
}
	public void numbers(){
	System.out.println("First nummber");		 
	  i = sc.nextInt();
	 lucky[0] = i%10;
	 
	 System.out.println("Second nummber");		 
	  i = sc.nextInt();
	 lucky[1] = i%10;
	
		System.out.println("Three'd nummber");		 
	 	i = sc.nextInt();
	 	lucky[2] = i%10;
	}
}


This post has been edited by chaos386: 09 November 2009 - 08:25 PM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1