Methods Summary |
---|
private void | checkNumbers()
for (int yourNumber = 0; yourNumber < numbers.length; yourNumber++)
{
for (int lottery = 0; lottery < lotteryNumbers.length; lottery++)
{
if (numbers[yourNumber] == lotteryNumbers[lottery])
{
number_equal++;
}
} // end of lottery loop
} // end of yourNumber loop
|
private void | determineResults()
switch(number_equal)
{
case 0:
case 1:
case 2: winnings = "Sorry - out of luck today";
break;
case 3: winnings = "Hey - small £10 winnings";
break;
case 4: winnings = "Things are looking up - £100";
break;
case 5: winnings = "Smile - you've just won £10,000";
break;
case 6: winnings = "Celebrate - you've just won £100,000";
break;
default:winnings = "Error - number_equals is " + number_equal + " out of range";
break;
}
|
private void | displayLotteryNumbers(java.awt.Graphics g)
for (int index = 0; index < lotteryNumbers.length; index++)
{
g.setColor(Color.blue) ;
g.drawOval(circleXPosition,circleYPosition,33,33) ;
g.setColor(Color.red);
g.drawString("" + lotteryNumbers[index], textXPosition,textYPosition);
circleXPosition = circleXPosition + 40 ;
textXPosition = textXPosition + 40 ;
}
|
private void | displayNumbers(java.awt.Graphics g)
textXPosition = 14 ;
textYPosition = 82 ;
// now add your numbers below the lottery balls
for (int index = 0; index < numbers.length; index++)
{
g.drawString("" + numbers[index], textXPosition, textYPosition);
textXPosition = textXPosition + 40;
}
|
public void | init()
numbers = new int[6];
lotteryNumbers = new int[7];
circleXPosition = 1 ;
circleYPosition = 20 ;
textXPosition = 12 ;
textYPosition = 42 ;
number_equal = 0;
|
private void | initialiseArray(int[] numArray)
for (int index = 0; index < numArray.length; index++)
{
numArray[index] = (int) (Math.random() * 49) + 1;
}
|
public void | paint(java.awt.Graphics g)
initialiseArray(lotteryNumbers); // set up lottery numbers
initialiseArray(numbers); // set up your numbers
sortArray(lotteryNumbers);
sortArray(numbers);
checkNumbers(); // compare your numbers with the lottery ones
displayLotteryNumbers(g); // print out the lottery number values
displayNumbers(g); // print out your numbers
determineResults(); // check to see if you have won anything
textYPosition = 102;
textXPosition = 12;
g.drawString(winnings,textXPosition,textYPosition);
|
private void | sortArray(int[] numArray)
int temp;
for (int outer = 0; outer < numArray.length - 1; outer++)
{
for (int inner = outer + 1; inner < numArray.length; inner++)
{
if (numArray[outer] > numArray[inner])
{
temp = numArray[outer];
numArray[outer] = numArray[inner];
numArray[inner] = temp;
}
}
}
|