Skip to content

Instantly share code, notes, and snippets.

@Justin42
Created January 21, 2012 07:46
Show Gist options
  • Save Justin42/1651943 to your computer and use it in GitHub Desktop.
Save Justin42/1651943 to your computer and use it in GitHub Desktop.
LotteryTicket
import java.util.Random;
import java.util.Arrays;
public class LotteryTicket
{
/**
* There are 6 numbers in each lottery ticket
*/
private final int TOTAL_NUMBERS = 6;
/**
* The smallest number on the ticket is assumed to be 1
* The largest number on the ticket is 49
*/
private final int MAX_NUMBER = 49;
/* FIXME: Include all necessary instance variables for a lottery ticket. */
/**
* This is the General Constructor. It should initialize and populate the
* lottery number into the array.
*/
public LotteryTicket()
{
/* FIXME: Fill in the necessary functionality in this method to create an
* array full of random numbers and sort it in ascending order - see Part I
* for guidance.
*/
}
/**
* This method populates the array a with numbers
* between MIN_NUMBER and MAX_NUMBER and ensures there are no duplicate numbers.
*/
private void generate (int[] a)
{
Random r = new Random();
for (int i=0;i<this.TOTAL_NUMBERS;i++)
{
/* FIXME: Complete the generate method. It should be very similar to the generate
* method used in Part 1.
*/
}
}
/**
* This method should return the numbers in the lottery ticket as a printable String,
* in the same format as the one used by the display method in Part 1.
*/
public String toString()
{
/* FIXME: */
return "{fixme}";
}
/**
* This method compares two sets of LotteryTicket and returns a boolean (true or false)
* indicating whether they match. LotteryDraw uses this method to determine if it has found a
* winning ticket, so it is very important that it function properly.
*/
public boolean matches(LotteryTicket other)
{
/*
* Based on the logic of this lottery program we know that for each Lottery Ticket:
* 1) all numbers are sorted lowest to highest
* 2) No numbers are the same
*
*/
/* FIXME: */
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment