• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Combination Lock

 
Christian Somody
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alright. I'm new to these forums, and to programming in Java as well, so don't laugh . Anyway, I got an assignment from my class that says:

Implement a combination lock class. A combination lock has a dial with 26 positions labeled A Z. The dial needs to be set three times. If it is set to the correct combination, the lock can be opened. When the lock is closed again, the combination can be entered again. If a user sets the dial more than three times, the last three settings determine whether the lock can be opened. You must use a class CombinationLock with a constructor that takes one three-letter String as its only parameter, a modifier setPosition() that takes a one-letter String as its only parameter, a modifier unlock() that opens the lock if the combination is correct, a predicate isOpen() to check the status of the lock, and a modifier lock() that closes the lock.

This is my code so far, and it doesn't work, and I really don't know why.



To me, the theory all looks fine. Maybe you can figure it out?
[ January 21, 2007: Message edited by: Christian Somody ]
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...it doesn't work, and I really don't know why.

What do you mean by "it doesn't work?" Are you getting any compiler errors, runtime exceptions, or is there a problem with the program logic. Please describe in detail what's happening, including the full text of any compiler or runtime error messages you are getting.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
are you still stuck, or has the problem been resolved from the replies here

http://forum.java.sun.com/thread.jspa?threadID=5126986&tstart=0
 
Christian Somody
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem was that it always said "Wrong combination!" but then was open if the combination was right (even though it said it was wrong). I forgot to use braces and I had two lines in the else statements. It was:


I fixed it now though. Thanks for the help .
[ January 21, 2007: Message edited by: Christian Somody ]
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic