It's been a while since i posted my last problem and my code looks alot different now so started a new thread instead instead of carrying on the old one (and the problems different).

**The project**

I have to design a Sweepstake game that has 2 classes Entrant and Sweepstake. Entrant is simply a class that holds the name and a contact number of someone entering the sweepstake.

The sweepstake class has two fields an array to store upto 20 entrants and a boolean to determine whether it is full or not.

Once 15 entrants or more have been added to the array then the sweepstake can be run, a random number 1-20 is chosen and the winner is printed out to the terminal.

**Entrant class**.

*(Only constructor, methods are just for returning the names and stuff)*

public class Entrant { private String name; private String contact; //Construct a new entrant storing a name and a contact number public Entrant(String enterName, String enterContact) { if(enterContact.length() >11 || enterContact.length()<11){ System.out.println("Contact numbers must be 11 digits"); } else{ name = enterName; contact = enterContact; } }

[b]My problem

**Sweepstake Class**.*(Haven't actually made the part that randomly selects the number and prints out the winner, but my problem doesn't concern that)*public class Sweepstake { //An array that stores upto 20 entrants. private Entrant[] numbers; // Boolean to determine whether all twenty numbers have been filled. private boolean full; /** * Create a new sweepstake with no numbers * and full set to false. */ public Sweepstake() { numbers = new Entrant[20]; full = false; } /** * Entrant enters a ticketnumber of there choosing, * their details are recorded against their number. */ public void buy_ticket(int number, Entrant entrant) { int indexPos = number -1; if(number >=1 && number <= 20 && numbers[indexPos]== null){ numbers[indexPos] = entrant; } else{ System.out.println("Sorry your number has been taken already"); System.out.println("Or you have entered a number that isn't between 1 and 20"); } } /** * Returns the numbers of the tickets that haven't * yet been sold. */ public void get_number_unsold() { int indexCount = 0; while(indexCount <=19){ if(numbers[indexCount] == null){ System.out.println("Number "+ (indexCount+1) +" is free"); } indexCount = indexCount+1; } } /** * Entrant recieves a random number that isn't already taken, * their details are recorded against their number. */ public void buy_random_ticket(Entrant entrant) { int randomTicket = 0; while(numbers[randomTicket] != null){ Random random = new Random(); randomTicket = (int)(Math.random()*20); } numbers[randomTicket] = entrant; } /** * Check to see if the sweepstake is full. */ public boolean full()

[b]My problem

I'm not sure how to go about with the boolean full. This in turn makes the buy random ticket go into an inifinite loop if the array is full as it just repeats until it finds an empty number (i can sort this out once i know how to do the full boolean.

The only way i can think of doing this is to have a count and do it like the way i did the get_unsold method. E.g. if the array index has an element in it a number is added onto a variable, once this variable hits 20 then it must be full so the boolean full = true. This just doesn't seem like the right way to do it though as surely if it's not full and you run it twice then the local variable would still have the exisiting number in it. So any guidance of how i go about doing it would help.

Thanks!

Oh one other thing this line

randomTicket = (int)(Math.random()*20);

from the buy random ticket method. Was wondering whether someone could just write this in pesuedo code for me, I searched the forums and found out how to write the method from another projects code. It works i just don't get what it means!