# Trying to compute a potential lottery winner based on the amount of ti

Page 1 of 1

## 8 Replies - 656 Views - Last Post: 04 March 2011 - 01:02 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=219896&amp;s=170b8f9748cb11d25254e8a7b9b38c65&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 dag72

Reputation: 1
• Posts: 205
• Joined: 02-March 11

# Trying to compute a potential lottery winner based on the amount of ti

Posted 02 March 2011 - 05:27 PM

Hello there,

I am trying write a program which allows user to input the amount of lottery tickets each player purchases then display a potential winner base on the largest amount of ticket that player purchased. Please see below for what i have done thus far, thus far this allows the user to enter the amount of purchase tickets against each player but i am not getting it to out the potential winner say for example 'lotteryPlayer6' because he/she purchase the most tickets.

Many thanks
```import java.util.Scanner;
/**
This program will allow a user to input the amount of tickets purchase by each player, then the total
amount will be calculated and output the amount
*
*
* @version (a version number or a date)
*/
public class LotteryPlayers1
{
public static void main(String []args)
{
Scanner in = new Scanner(System.in);
//int lotteryPlayer1 = 0;
//int lotteryPlayer2 = 0;
//int lotteryPlayer3 = 0;
//int lotteryPlayer4 = 0;
//int lotteryPlayer5 = 0;
//int lotteryPlayer6 = 0;

System.out.print("Please enter amount of tickets purchase by player1: ");
int lotteryPlayer1 = in. nextInt();
System.out.print("Please enter amount of tickets purchase by player2: ");
int lotteryPlayer2 = in. nextInt();
System.out.print("Please enter amount of tickets purchase by player3: ");
int lotteryPlayer3 = in. nextInt();
System.out.print("Please enter amount of tickets purchase by player4: ");
int lotteryPlayer4 = in. nextInt();
System.out.print("Please enter amount of tickets purchase by player5: ");
int lotteryPlayer5 = in. nextInt();
System.out.print("Please enter amount of tickets purchase by player6: ");
int lotteryPlayer6 = in. nextInt();
//System.out.println(lotteryPlayer1+lotteryPlayer2+lotteryPlayer3+lotteryPlayer4+lotteryPlayer5+lotteryPlayer6);
System.out.print("Enter the most ticket sales to see the favorite chance: ");
int lotteryPlayer = in. nextInt();

int potentialWinner = 0;
if (lotteryPlayer >= 100)
{
potentialWinner = lotteryPlayer;
}
else

{
potentialWinner = 0;
}
System.out.println("the potential winner is: "+potentialWinner+lotteryPlayer);
}
}

```

This post has been edited by pbl: 02 March 2011 - 05:29 PM
Reason for edit:: Code tags added

Is This A Good Question/Topic? 0

## Replies To: Trying to compute a potential lottery winner based on the amount of ti

### #2 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 12298
• Posts: 45,399
• Joined: 27-December 08

## Re: Trying to compute a potential lottery winner based on the amount of ti

Posted 02 March 2011 - 05:36 PM

You should really store an int[], and populate your choices into the array. Then just loop through the array to find the max.

### #3 pbl

• There is nothing you can't do with a JTable

Reputation: 8378
• Posts: 31,956
• Joined: 06-March 08

## Re: Trying to compute a potential lottery winner based on the amount of ti

Posted 02 March 2011 - 05:36 PM

All what your program does is:

```    System.out.print("Enter the most ticket sales to see the favorite chance: ");
int lotteryPlayer = in. nextInt();

int potentialWinner = 0;
if (lotteryPlayer >= 100)
{
potentialWinner = lotteryPlayer;
}
System.out.println("the potential winner is: "+potentialWinner+lotteryPlayer);
}

```

So you input a number from the user
if this number is >= 100 you print that number * 2
else you output that number

### #4 dag72

Reputation: 1
• Posts: 205
• Joined: 02-March 11

## Re: Trying to compute a potential lottery winner based on the amount of ti

Posted 03 March 2011 - 02:52 AM

macosxnerd101, on 02 March 2011 - 05:36 PM, said:

You should really store an int[], and populate your choices into the array. Then just loop through the array to find the max.

Many thanks, this is very helpful tried that and it is looking better now; still not there yet but its coming. As i am a newbie to this programming thing it will take me a day or two to finally get it working.

pbl, on 02 March 2011 - 05:36 PM, said:

All what your program does is:

```    System.out.print("Enter the most ticket sales to see the favorite chance: ");
int lotteryPlayer = in. nextInt();

int potentialWinner = 0;
if (lotteryPlayer >= 100)
{
potentialWinner = lotteryPlayer;
}
System.out.println("the potential winner is: "+potentialWinner+lotteryPlayer);
}

```

So you input a number from the user
if this number is >= 100 you print that number * 2
else you output that number

Many thanks

### #5 dag72

Reputation: 1
• Posts: 205
• Joined: 02-March 11

## Re: Trying to compute a potential lottery winner based on the amount of ti

Posted 03 March 2011 - 04:16 PM

Hello there, I have revised this code and get it to print out a string of largest players but the value besides each are all 0 not sure whats going on any suggestions? Please see below.
```import java.util.Scanner;
/**
This program will allow a user to input the amount of tickets purchase by each player, then the total
amount will be calculated and output the amount
*
* @author (by Dave Gordon)
* @version (a version number or a date)
*/
public class LotteryPlayers1
{
public static void main(String []args)
{
Scanner in = new Scanner(System.in);
final int LENGTH = 10;
int[] data = new int[LENGTH];
//int lotteryPlayers = 0;
//int lotteryPlayer1 = 0;
//int lotteryPlayer2 = 0;
//int lotteryPlayer3 = 0;
//int lotteryPlayer4 = 0;
//int lotteryPlayer5 = 0;
//int lotteryPlayer6 = 0;

System.out.print("Please enter amount of tickets purchase by player1: ");
int lotteryPlayer1 = in. nextInt();
System.out.print("Please enter amount of tickets purchase by player2: ");
int lotteryPlayer2 = in. nextInt();
System.out.print("Please enter amount of tickets purchase by player3: ");
int lotteryPlayer3 = in. nextInt();
System.out.print("Please enter amount of tickets purchase by player4: ");
int lotteryPlayer4 = in. nextInt();
System.out.print("Please enter amount of tickets purchase by player5: ");
int lotteryPlayer5 = in. nextInt();
System.out.print("Please enter amount of tickets purchase by player6: ");
int lotteryPlayer6 = in. nextInt();
//System.out.println(lotteryPlayer1+lotteryPlayer2+lotteryPlayer3+lotteryPlayer4+lotteryPlayer5+lotteryPlayer6);
System.out.println("The highest player's chance of winning ");
//int lotteryPlayer = in. nextInt();

int largestPlayer = data[0];
for (int i = 1; i < largestPlayer; i++)
{
if (data[i] > largestPlayer)
{
largestPlayer = data[i];

}
}
for (int i = 0; i < largestPlayer; i++)
{
System.out.print(data[i]);
if (data[i] == largestPlayer)
{
System.out.print(" <== largest player");
}
System.out.println();
}
}
}
//}

```

This post has been edited by macosxnerd101: 03 March 2011 - 05:04 PM
Reason for edit:: Please use code tags!!!

### #6 kevin_mchugh

Reputation: 11
• Posts: 75
• Joined: 08-April 09

## Re: Trying to compute a potential lottery winner based on the amount of ti

Posted 03 March 2011 - 05:02 PM

Hello,

You appear to have gotten a bit confused. So I will try to help you out.

Firstly,

```System.out.print("Please enter amount of tickets purchase by player1: ");
data[0] = in. nextInt();

```

This will store the first value typed in into your array. You just move onto the next one by incrementing the data element to "data[1]" and so on.

The in order to loop through them all you would use this.

```for(int x=0; x<data.lenght();x++){

data[x]...........
}

```

Again, if anyone else disagrees feel free to flame me. Beyond that, well I think I would just be writing the code for you.

However if you have any more questions....just ask :-)

Later

This post has been edited by kevin_mchugh: 03 March 2011 - 05:03 PM

### #7 pbl

• There is nothing you can't do with a JTable

Reputation: 8378
• Posts: 31,956
• Joined: 06-March 08

## Re: Trying to compute a potential lottery winner based on the amount of ti

Posted 03 March 2011 - 05:13 PM

Where is the data[] array populated beside for data[0] ?

### #8 dag72

Reputation: 1
• Posts: 205
• Joined: 02-March 11

## Re: Trying to compute a potential lottery winner based on the amount of ti

Posted 04 March 2011 - 12:39 AM

kevin_mchugh, on 03 March 2011 - 05:02 PM, said:

Hello,

You appear to have gotten a bit confused. So I will try to help you out.

Firstly,

```System.out.print("Please enter amount of tickets purchase by player1: ");
data[0] = in. nextInt();

```

This will store the first value typed in into your array. You just move onto the next one by incrementing the data element to "data[1]" and so on.

The in order to loop through them all you would use this.

```for(int x=0; x<data.lenght();x++){

data[x]...........
}

```

Again, if anyone else disagrees feel free to flame me. Beyond that, well I think I would just be writing the code for you.

However if you have any more questions....just ask :-)

Later

Hello

Thanks for your help it really makes things clearer, just to clarify are you saying i need to replace each variables int lotteryPlayer? = in.nextInt()with data[?]= in.nextInt();

Regards

### #9 dag72

Reputation: 1
• Posts: 205
• Joined: 02-March 11

## Re: Trying to compute a potential lottery winner based on the amount of ti

Posted 04 March 2011 - 01:02 AM

dag72, on 04 March 2011 - 12:39 AM, said:

kevin_mchugh, on 03 March 2011 - 05:02 PM, said:

Hello,

You appear to have gotten a bit confused. So I will try to help you out.

Firstly,

```System.out.print("Please enter amount of tickets purchase by player1: ");
data[0] = in. nextInt();

```

This will store the first value typed in into your array. You just move onto the next one by incrementing the data element to "data[1]" and so on.

The in order to loop through them all you would use this.

```for(int x=0; x<data.lenght();x++){

data[x]...........
}

```

Again, if anyone else disagrees feel free to flame me. Beyond that, well I think I would just be writing the code for you.

However if you have any more questions....just ask :-)

Later

Hello

Thanks for your help it really makes things clearer, just to clarify are you saying i need to replace each variables int lotteryPlayer? = in.nextInt()with data[?]= in.nextInt();

Regards

Hello

Thanks again man, you are a genius this has solved my problem.