Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package rainfall;
- /**
- *
- * @author Paul x13125974
- */
- import javax.swing.JOptionPane;
- public class RainfallApp {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // TODO code application logic here
- //create and initilise arrays
- int line1 = 0;
- int line2 = 0;
- int line3 =0;
- int[][] lotto = new int[3][5];
- int[] winningNum = new int[5];
- int not1 = 0;
- int not2 = 0;
- int not3 = 0;
- //generating 5 randon numbers between 1 - 40 and storing them in the array called "winningNum"
- for (int i = 0; i < winningNum.length; i++) {
- winningNum[i] = (int)Math.floor (1+Math.random() * 40);
- // prints the 5 random numbers to the console
- System.out.println(winningNum[i]);
- }
- //User input - CHANGED BY VLAD
- for (int i = 0; i < lotto.length; i++) {
- for (int j = 0; j < lotto[0].length; j++) {
- lotto[i][j] = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter the number for line " + (i + 1) + ", number " + (j + 1) + " : "));
- }
- }
- //CHANGED BY VLAD
- for (int i = 0; i < 1; i++) {
- for (int j = 0; j < 5; j++) {//row 1
- 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]) {
- line1++;
- } else {
- not1++;
- }
- }
- }
- //CHANGED BY VLAD
- for (int i = 1; i < 2; i++) {
- for (int j = 0; j < 5; j++) {//row 2
- 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]) {
- line2++;
- } else {
- not2++;
- }
- }
- }
- //CHANGED BY VLAD
- for (int i = 2; i < 3; i++) {//row 3
- for (int j = 0; j < 5; j++) {
- 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]) {
- line3++;
- } else {
- not3++;
- }
- }
- }
- //loop and selection statement comparring arrays
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 5; j++) {
- if (lotto[i][j] == winningNum[j]) {
- JOptionPane.showMessageDialog(null, "The numbers you matched across all three lines are " + winningNum[j]);
- }
- System.out.print(lotto[i][j]);
- }
- System.out.println();
- }
- JOptionPane.showMessageDialog(null, "You guessed " + line1 + " numbers corectly on line 1");
- JOptionPane.showMessageDialog(null, "You guessed " + line2 + " numbers corectly on line 2");
- JOptionPane.showMessageDialog(null, "You guessed " + line3 + " numbers corectly on line 3");
- System.out.println(not1);
- System.out.println(not2);
- System.out.println(not3);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement