Ok, so I'm trying to make a combination lock using Java. The combo has to be a three letter combination.
First for the main bit.
Now for the tester.
The problem is that it keeps saying that "The Lock Is Not Opened" no matter what I do. What am I doing wrong?
Thanks in advance.
You have to:
1) In the lock's constructor set the combination to the string passed into the constructor (so the String you asked for means something).
2) When you ask for a position, you call setPosition, but that method doesn't set any positions. So you will have to modify it so it does.
3) When you make the comparison you are hard-coding the test to see if the combination is "BOB". you should change that comparison to test if the sum of the guessed positions equals the combination.
... however, now it just says this after I run the program and input everything:
----jGRASP exec: java CombinationLockTest
Exception in thread "main" java.lang.NullPointerException
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
Something is wrong with "public boolean unlock()," but I can't quite place it.....
After this, I think I'll be done!
for the record, unlock is now:
You de-reference (call a method on) aPosition, but you haven't assigned a value to the variable named aPosition, so it is null. As a result you get a NullPointerEcception. Resolve it by assigning the appropriate value to aPosition.