Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* By Sunny Mahant
- * Class ICS4M0-A
- * Lottery.java, created April 16,2008
- * This is a lottey program whic ask the user to enter a quick pick or actually choose the numbers then it prints the ticket and check the numbers
- */
- import java.awt.*;
- import hsa.Console;
- public class Lottery
- {
- static Console c; // The output console
- static int choice, i, x, y, z, k, temp, min, j;// declared as global variables
- static int lotto[] = new int [4];// declared as global array
- public static int menu ()// menu method
- {
- c.println ("\t\tWelcome To The Sunshine Lottery ");
- c.println ("Quick Pick Press 1");
- c.println ("Choose the Numbers Press 2");
- choice = c.readInt ();
- if (choice == 1)
- {
- quickPick ();
- }
- else if (choice == 2)
- {
- choose ();
- }
- return choice;
- }
- public static int quickPick ()
- {
- for (i = 0 ; i < 4 ; i++)
- {
- lotto [i] = (int) Math.ceil (Math.random () * 10);
- }
- for (x = 0 ; x < lotto.length - 1 ; x++)
- {
- min = x;
- for (j = x + 1 ; j < lotto.length ; j++)
- {
- if (lotto [j] < lotto [min])
- min = j;
- }
- temp = lotto [x];
- lotto [x] = lotto [min];
- lotto [min] = temp;
- }
- c.println ("\t\t\t*****************************");
- c.println ("\t\t\t* The Sunshine Lottery ^_^ *");
- c.println ("\t\t\t*****************************");
- c.print ("\t\t\t*");
- for (i = 0 ; i < lotto.length ; i++)
- {
- c.print (" " + lotto [i]);
- }
- c.print ("\t *\n");
- c.println ("\t\t\t* *");
- c.println ("\t\t\t* *");
- c.println ("\t\t\t* Good Luck *");
- c.println ("\t\t\t*****************************"); //These lines prints ticket
- return lotto [i];
- }
- public static int choose ()
- {
- c.println ("please choose 4 numbers between 1-10");
- for (k = 0 ; k < 4 ; k++)
- {
- lotto [k] = c.readInt ();
- }
- for (x = 0 ; x < lotto.length - 1 ; x++)
- {
- min = x;
- for (j = x + 1 ; j < lotto.length ; j++)
- {
- if (lotto [j] < lotto [min])
- min = j;
- }
- temp = lotto [x];
- lotto [x] = lotto [min];
- lotto [min] = temp;
- }
- c.println ("\t\t\t*****************************");
- c.println ("\t\t\t* The Sunshine Lottery ^_^ *");
- c.println ("\t\t\t*****************************");
- c.print ("\t\t\t*");
- for (k = 0 ; k < lotto.length ; k++)
- {
- c.print (" " + lotto [k]);
- }
- c.print ("\t *\n");
- c.println ("\t\t\t* *");
- c.println ("\t\t\t* *");
- c.println ("\t\t\t* Good Luck *");
- c.println ("\t\t\t*****************************"); //These lines prints ticket
- return lotto [k];
- }
- public static void main (String[] args)
- {
- c = new Console ();
- menu ();
- int lotto2[] = new int [4];
- int total;
- c.println (" The winning numbers are...");
- for (z = 0 ; z < 3 ; z++)
- {
- lotto2 [z] = (int) Math.ceil (Math.random () * 10);
- }
- for (x = 0 ; x < lotto2.length - 1 ; x++)
- {
- min = x;
- for (j = x + 1 ; j < lotto2.length ; j++)
- {
- if (lotto2 [j] < lotto2 [min])
- min = j;
- }
- temp = lotto2 [x];
- lotto2 [x] = lotto2 [min];
- lotto2 [min] = temp;
- }
- for (z = 0 ; z < lotto2.length ; z++)
- {
- c.print (lotto2 [z]);
- }
- if (choice == 1)
- {
- total = lotto[i];
- }
- if (choice == 2)
- {
- total = lotto[k];
- }
- if (lotto [1] == lotto2 [1])
- {
- c.println (" first number match");
- }
- else
- {
- c.println (" doesnt match");
- }
- if (lotto [2] == lotto2 [2])
- {
- c.println (" first number match");
- }
- else
- {
- c.println (" doesnt match");
- }
- if (lotto [3] == lotto2 [3])
- {
- c.println (" first number match");
- }
- else
- {
- c.println (" doesnt match");
- }
- if (lotto [0] == lotto2 [0])
- {
- c.println (" first number match");
- }
- else
- {
- c.println (" doesnt match");
- }
- // Place your program here. 'c' is the output console
- } // main method
- } // Lottery class
Add Comment
Please, Sign In to add comment