Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.06 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. class lotto {
  4.  
  5. public ArrayList<Integer> oneNumber = GetNumber();
  6. public ArrayList<Integer> lottoDraw = GetNumbers();
  7. public ArrayList<Double> howmanyTimes = new ArrayList<Double>();
  8. public ArrayList<Double> outcome = new ArrayList<Double>();
  9. public ArrayList<Double> nums = new ArrayList<Double>();
  10. public ArrayList<Integer> times = new ArrayList<Integer>();
  11. public ArrayList<String> storeLotnum = new ArrayList<String>();
  12.  
  13. //Creating multidimensional arraylist. {{0},{1},{2},{3},{4},{5},{6},{7},{8}}
  14. public ArrayList<ArrayList<String>> all = new ArrayList<ArrayList<String>>();
  15.  
  16. //Draw one bonus number.
  17. public static ArrayList<Integer> GetNumber() {
  18.  
  19. ArrayList<Integer> bonusNumber = new ArrayList<Integer>();
  20.  
  21. //We only need one random bonusnumber.
  22. bonusNumber.add((int) ((40 * Math.random()) + 1));
  23.  
  24. return bonusNumber;
  25. }
  26.  
  27. //Get lottotickets and draw one "correct" lottonumber.
  28. public static ArrayList<Integer> GetNumbers() {
  29.  
  30. ArrayList<Integer> allNum = new ArrayList<Integer>();
  31.  
  32. //First adding all 40 numbers.
  33. for (int i = 1; i < 41; i++) {
  34. allNum.add(i);
  35. }
  36. //Shuffle because we dont wanna dublicates.
  37. Collections.shuffle(allNum);
  38.  
  39. ArrayList<Integer> lottoNum = new ArrayList<Integer>();
  40.  
  41. //Adding 7 numbers to list.
  42. for (int i = 0; i < 7; i++) {
  43. lottoNum.add(allNum.get(i));
  44. }
  45. //Sorting lottonum from smaller to bigger number.
  46. Collections.sort(lottoNum);
  47.  
  48. return lottoNum;
  49. }
  50.  
  51. //Prints the correct lottonumbers.
  52. public void ShowCorrectlottonum(){
  53. System.out.print("\n");
  54. System.out.println("Lottery correct numbers: " + lottoDraw + " + " + "[" + oneNumber.get(0) + "]");
  55. System.out.print("\n");
  56. }
  57.  
  58. public void PlayLotto(double num){
  59. //Filling nums list.
  60. for(int i = 0; i < 9; i++) {
  61. nums.add(0.0);
  62. }
  63.  
  64. //Adding 9 rows to "all" list.
  65. for(int i = 0; i < 9; i++) {
  66. all.add(new ArrayList<String>());
  67. }
  68.  
  69. //Looping all played tickets.
  70. for (int i = 0; i < num; i++) {
  71. ArrayList<Integer> lottoNum2 = GetNumbers();
  72. ArrayList<Integer> storage = new ArrayList<Integer>(lottoDraw); //Put the correct lottonumbers to storage, so you can check how many numbers are correct.
  73.  
  74. //Lottonumber to string.
  75. String listString = lottoNum2.toString();
  76. listString = listString.substring(1, listString.length()-1);
  77. storeLotnum.add(listString);
  78.  
  79. //Removing elements from storage that are not contained in the lottonum2.
  80. storage.retainAll(lottoNum2);
  81.  
  82. int idx = storage.size();
  83. double value = nums.get(idx);
  84.  
  85. //Checking storage size = how many numbers are correct, adding one into variable and then adding lottoNum to string list.
  86. if(idx == 6 && lottoNum2.contains(oneNumber.get(0))) {
  87. nums.set(8, (nums.get(8) + 1));
  88. all.get(8).add(listString);
  89. }
  90. else if(idx >= 4) {
  91. nums.set(idx,value + 1);
  92. all.get(idx).add(listString);
  93. }
  94. else {
  95. value = nums.get(0) + 1;
  96. nums.set(0,value);
  97. }
  98. }
  99. //Adding variables,counting probability and converting to int.
  100. for(int i = 0; i < nums.size(); i++) {
  101. howmanyTimes.add(i, nums.get(i));
  102. outcome.add(i, (howmanyTimes.get(i)/num)*100);
  103. times.add(howmanyTimes.get(i).intValue());
  104. }
  105. }
  106.  
  107. //Prints all played tickets.
  108. public void ShowTickets(){
  109. for(int i = 0; i < storeLotnum.size(); i++) {
  110. System.out.println("\n" + storeLotnum.get(i) + "\n");
  111. }
  112. }
  113.  
  114. //Prints all winningnumbers.
  115. public void ShowWinningnumbers(){
  116. //Looping backwords.
  117. for(int i = 7; i > 3; i--) {
  118. if(i > 3) this.PrintTicket(i);
  119. if(i == 7) this.PrintTicket(8);
  120. }
  121. }
  122. private void PrintTicket(int idx){
  123. String[] correctNum = {"0","1","2","3","4","5","6","7","6+1"};
  124. System.out.printf("\n|All %s correct numbers|\n", correctNum[idx]);
  125.  
  126. //Looping list and print.
  127. for(int j = 0; j < all.get(idx).size(); j++) {
  128. System.out.println(all.get(idx).get(j) + "\n");
  129. }
  130. }
  131.  
  132. //Prints how many pcs. in every categories.
  133. public void ShowAllwinning(){
  134. System.out.println("|The number of winning categories|");
  135. System.out.printf("7 correct: \t\t%d pcs.\n6+1 correct: \t\t%d pcs.\n6 correct: \t\t%d pcs.\n5 correct: \t\t%d pcs.\n4 correct: \t\t%d pcs.\nTickets with no win: \t%d pcs.\n",times.get(7),times.get(8),times.get(6),times.get(5),times.get(4),times.get(0));
  136. System.out.print("\n");
  137. }
  138.  
  139. //Prints probabilities.
  140. public void ShowOdds(){
  141. System.out.println("|Probabilities|");
  142. System.out.printf("7 correct: \t\t%.10f%%\n6+1 correct: \t\t%.10f%%\n6 correct: \t\t%.10f%%\n5 correct: \t\t%.10f%%\n4 correct: \t\t%.10f%%\n", outcome.get(7),outcome.get(8),outcome.get(6),outcome.get(5),outcome.get(4));
  143. }
  144. }
  145. //PÄÄOHJELMA.
  146. public class javaykskolme {
  147.  
  148. public static void main(String[] args) {
  149.  
  150. lotto newlotto = new lotto();
  151.  
  152. newlotto.PlayLotto(18000000);
  153. //newlotto.ShowTickets();
  154. newlotto.ShowCorrectlottonum();
  155. newlotto.ShowWinningnumbers();
  156. newlotto.ShowCorrectlottonum();
  157. newlotto.ShowAllwinning();
  158. newlotto.ShowOdds();
  159. }
  160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement