• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need help creating a combination Lock that consist of three strings.

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
//My only issue is my set position method. In this method I need to use a counter to keep track of user's input. But i am not sure how to do that.
In this class I am trying to create a combination lock that takes three strings. In the tester class the user inserts three strings and both are compared to see if users input matches correct combination. I have no errors only problem is the setPosition method. My output is always false.






 
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A quick pointer on the issue..

in setPosition move the initializing of counter to where the variable is declared. you don't want the variable to be initialized each time the method is called.
move counter++ to the bottom of the method. Then try..
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

I have corrected your code tags; you can find out how to use them here. I also got rid of some of the unnecessary blank lines, which don't enhance legibility. Lines like this are particularly difficult to read because of their length and lack of spaces between successive tokens:-Your inconsistent indentation is because you are mixing spaces and tabs. Look at our suggestions. Correcting those things will get you better marks and that is what you want

Do you know how to write arrays? If so, you could replace the several ifs in lines 33-43 with arrays and indices. You might pass the three guesses to one method call and get rid of the counter variable, as an alternative.
 
Proudly marching to the beat of a different kettle of fish... while reading this tiny ad
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic