Guest User

Untitled

a guest
Apr 23rd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.15 KB | None | 0 0
  1. /* By Sunny Mahant
  2. * Class ICS4M0-A
  3. * Lottery.java, created April 16,2008
  4. * 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
  5. */
  6. import java.awt.*;
  7. import hsa.Console;
  8.  
  9. public class Lottery
  10. {
  11. static Console c; // The output console
  12. static int choice, i, x, y, z, k, temp, min, j;// declared as global variables
  13. static int lotto[] = new int [4];// declared as global array
  14.  
  15. public static int menu ()// menu method
  16. {
  17.  
  18.  
  19. c.println ("\t\tWelcome To The Sunshine Lottery ");
  20. c.println ("Quick Pick Press 1");
  21. c.println ("Choose the Numbers Press 2");
  22. choice = c.readInt ();
  23. if (choice == 1)
  24. {
  25. quickPick ();
  26.  
  27. }
  28. else if (choice == 2)
  29. {
  30. choose ();
  31.  
  32. }
  33. return choice;
  34. }
  35.  
  36.  
  37. public static int quickPick ()
  38. {
  39.  
  40.  
  41.  
  42. for (i = 0 ; i < 4 ; i++)
  43. {
  44. lotto [i] = (int) Math.ceil (Math.random () * 10);
  45.  
  46.  
  47. }
  48.  
  49. for (x = 0 ; x < lotto.length - 1 ; x++)
  50. {
  51. min = x;
  52. for (j = x + 1 ; j < lotto.length ; j++)
  53. {
  54. if (lotto [j] < lotto [min])
  55. min = j;
  56. }
  57. temp = lotto [x];
  58. lotto [x] = lotto [min];
  59. lotto [min] = temp;
  60. }
  61.  
  62.  
  63.  
  64. c.println ("\t\t\t*****************************");
  65. c.println ("\t\t\t* The Sunshine Lottery ^_^ *");
  66. c.println ("\t\t\t*****************************");
  67. c.print ("\t\t\t*");
  68. for (i = 0 ; i < lotto.length ; i++)
  69. {
  70.  
  71. c.print (" " + lotto [i]);
  72. }
  73.  
  74. c.print ("\t *\n");
  75. c.println ("\t\t\t* *");
  76. c.println ("\t\t\t* *");
  77. c.println ("\t\t\t* Good Luck *");
  78. c.println ("\t\t\t*****************************"); //These lines prints ticket
  79.  
  80.  
  81.  
  82.  
  83. return lotto [i];
  84.  
  85.  
  86.  
  87. }
  88.  
  89.  
  90. public static int choose ()
  91. {
  92.  
  93. c.println ("please choose 4 numbers between 1-10");
  94. for (k = 0 ; k < 4 ; k++)
  95. {
  96. lotto [k] = c.readInt ();
  97. }
  98.  
  99. for (x = 0 ; x < lotto.length - 1 ; x++)
  100. {
  101. min = x;
  102. for (j = x + 1 ; j < lotto.length ; j++)
  103. {
  104. if (lotto [j] < lotto [min])
  105. min = j;
  106. }
  107. temp = lotto [x];
  108. lotto [x] = lotto [min];
  109. lotto [min] = temp;
  110. }
  111. c.println ("\t\t\t*****************************");
  112. c.println ("\t\t\t* The Sunshine Lottery ^_^ *");
  113. c.println ("\t\t\t*****************************");
  114. c.print ("\t\t\t*");
  115. for (k = 0 ; k < lotto.length ; k++)
  116. {
  117.  
  118. c.print (" " + lotto [k]);
  119. }
  120.  
  121. c.print ("\t *\n");
  122. c.println ("\t\t\t* *");
  123. c.println ("\t\t\t* *");
  124. c.println ("\t\t\t* Good Luck *");
  125. c.println ("\t\t\t*****************************"); //These lines prints ticket
  126.  
  127. return lotto [k];
  128.  
  129. }
  130.  
  131.  
  132.  
  133.  
  134. public static void main (String[] args)
  135. {
  136. c = new Console ();
  137. menu ();
  138.  
  139. int lotto2[] = new int [4];
  140. int total;
  141. c.println (" The winning numbers are...");
  142. for (z = 0 ; z < 3 ; z++)
  143. {
  144. lotto2 [z] = (int) Math.ceil (Math.random () * 10);
  145.  
  146.  
  147. }
  148.  
  149.  
  150. for (x = 0 ; x < lotto2.length - 1 ; x++)
  151. {
  152. min = x;
  153. for (j = x + 1 ; j < lotto2.length ; j++)
  154. {
  155. if (lotto2 [j] < lotto2 [min])
  156. min = j;
  157. }
  158. temp = lotto2 [x];
  159. lotto2 [x] = lotto2 [min];
  160. lotto2 [min] = temp;
  161. }
  162.  
  163.  
  164. for (z = 0 ; z < lotto2.length ; z++)
  165. {
  166.  
  167. c.print (lotto2 [z]);
  168. }
  169.  
  170.  
  171. if (choice == 1)
  172. {
  173. total = lotto[i];
  174. }
  175.  
  176.  
  177. if (choice == 2)
  178. {
  179. total = lotto[k];
  180. }
  181.  
  182.  
  183. if (lotto [1] == lotto2 [1])
  184. {
  185. c.println (" first number match");
  186. }
  187.  
  188.  
  189. else
  190. {
  191. c.println (" doesnt match");
  192. }
  193.  
  194.  
  195. if (lotto [2] == lotto2 [2])
  196. {
  197. c.println (" first number match");
  198. }
  199.  
  200.  
  201. else
  202. {
  203. c.println (" doesnt match");
  204. }
  205.  
  206.  
  207. if (lotto [3] == lotto2 [3])
  208. {
  209. c.println (" first number match");
  210. }
  211.  
  212.  
  213. else
  214. {
  215. c.println (" doesnt match");
  216. }
  217.  
  218.  
  219. if (lotto [0] == lotto2 [0])
  220. {
  221. c.println (" first number match");
  222. }
  223.  
  224.  
  225. else
  226. {
  227. c.println (" doesnt match");
  228. }
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235. // Place your program here. 'c' is the output console
  236. } // main method
  237. } // Lottery class
Add Comment
Please, Sign In to add comment