Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.83 KB | None | 0 0
  1.  
  2. /*
  3. * To change this license header, choose License Headers in Project Properties.
  4. * To change this template file, choose Tools | Templates
  5. * and open the template in the editor.
  6. */
  7. package rainfall;
  8.  
  9. /**
  10. *
  11. * @author Paul x13125974
  12. */
  13. import javax.swing.JOptionPane;
  14.  
  15. public class RainfallApp {
  16.  
  17. /**
  18. * @param args the command line arguments
  19. */
  20. public static void main(String[] args) {
  21. // TODO code application logic here
  22.  
  23. //create and initilise arrays
  24. int line1 = 0;
  25. int line2 = 0;
  26. int line3 =0;
  27. int[][] lotto = new int[3][5];
  28. int[] winningNum = new int[5];
  29. int not1 = 0;
  30. int not2 = 0;
  31. int not3 = 0;
  32.  
  33. //generating 5 randon numbers between 1 - 40 and storing them in the array called "winningNum"
  34. for (int i = 0; i < winningNum.length; i++) {
  35. winningNum[i] = (int)Math.floor (1+Math.random() * 40);
  36.  
  37. // prints the 5 random numbers to the console
  38. System.out.println(winningNum[i]);
  39. }
  40.  
  41. //User input - CHANGED BY VLAD
  42. for (int i = 0; i < lotto.length; i++) {
  43. for (int j = 0; j < lotto[0].length; j++) {
  44. lotto[i][j] = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter the number for line " + (i + 1) + ", number " + (j + 1) + " : "));
  45. }
  46. }
  47.  
  48. //CHANGED BY VLAD
  49. for (int i = 0; i < 1; i++) {
  50. for (int j = 0; j < 5; j++) {//row 1
  51. if (winningNum[j] == lotto[i][0] || winningNum[j] == lotto[i][1] || winningNum[j] == lotto[i][2] || winningNum[j] == lotto[i][3] || winningNum[j] == lotto[i][4]) {
  52. line1++;
  53.  
  54. } else {
  55. not1++;
  56.  
  57. }
  58.  
  59. }
  60. }
  61.  
  62. //CHANGED BY VLAD
  63. for (int i = 1; i < 2; i++) {
  64. for (int j = 0; j < 5; j++) {//row 2
  65. if (winningNum[j] == lotto[i][0] || winningNum[j] == lotto[i][1] || winningNum[j] == lotto[i][2] || winningNum[j] == lotto[1][3] || generatedNumbers[j] == lotto[i][4]) {
  66. line2++;
  67.  
  68. } else {
  69. not2++;
  70. }
  71. }
  72. }
  73. //CHANGED BY VLAD
  74. for (int i = 2; i < 3; i++) {//row 3
  75. for (int j = 0; j < 5; j++) {
  76. if (winningNum[j] == lotto[i][0] || winningNum[j] == lotto[i][1] || winningNum[j] == lotto[i][2] || winningNum[j] == lotto[1][3] || winningNum[j] == lotto[i][4]) {
  77. line3++;
  78.  
  79. } else {
  80. not3++;
  81. }
  82. }
  83. }
  84.  
  85. //loop and selection statement comparring arrays
  86. for (int i = 0; i < 3; i++) {
  87. for (int j = 0; j < 5; j++) {
  88. if (lotto[i][j] == winningNum[j]) {
  89. JOptionPane.showMessageDialog(null, "The numbers you matched across all three lines are " + winningNum[j]);
  90.  
  91. }
  92.  
  93. System.out.print(lotto[i][j]);
  94.  
  95. }
  96. System.out.println();
  97.  
  98. }
  99.  
  100. JOptionPane.showMessageDialog(null, "You guessed " + line1 + " numbers corectly on line 1");
  101. JOptionPane.showMessageDialog(null, "You guessed " + line2 + " numbers corectly on line 2");
  102. JOptionPane.showMessageDialog(null, "You guessed " + line3 + " numbers corectly on line 3");
  103. System.out.println(not1);
  104. System.out.println(not2);
  105. System.out.println(not3);
  106.  
  107. }
  108.  
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement