I'm new to Java and I'm trying to figure out how to do this example. I originally planned to store the 3 user guesses into an Array called UserGuess and store the 3 attempted guesses in another array, but I'm confused as to how I would store USER input into an array(I've only been using fixed numbers). I'm also confused as to how I would write out if the UserGuess array's integers are equal to the ones of the attempted guesses, a messagebox would appear indicating the lock is opened or the attempted guesses were wrong.
package ComboLockerDrive;
import javax.swing.JOptionPane;
public class ComboLockerDrive {
public static void main(String[] args) {
int digit1 = Integer.parseInt(JOptionPane.showInputDialog("Enter the first digit of your locker combo: "));
int digit2 = Integer.parseInt(JOptionPane.showInputDialog("Enter the second digit of your locker combo: "));
int digit3 = Integer.parseInt(JOptionPane.showInputDialog("Enter the third digit of your locker combo: "));
System.out.println("The code has been set!");
int[] combination = new int[3];
combination[0] = digit1;
combination[1] = digit2;
combination[2] = digit3;
System.out.println("Now we will try and open the lock!");
int[] attemptedGuess = new int[3];
int Guess1 = Integer.parseInt(JOptionPane.showInputDialog("Enter your first guess: "));
int Guess2 = Integer.parseInt(JOptionPane.showInputDialog("Enter your second guess: "));
int Guess3 = Integer.parseInt(JOptionPane.showInputDialog("Enter your third guess: "));
attemptedGuess[0] = Guess1;
attemptedGuess[1] = Guess2;
attemptedGuess[2] = Guess3;
if(combination == attemptedGuess) {
System.out.println("The lock opened, congratulations, you got the combination right!");
}
else {
System.out.println("The lock does not open, the combination you tried was incorrect");
}
}
}
This is what I have so far, no errors whatsoever, but when I enter the correct combination, it says that the combination is incorrect. Does this mean I didn't fill the array in properly?