KeyPadLock

Hi, I have to write java code for a KeyPadLock class I need some help with the the variable declarations and a constructors
First I'm assigning elements to one of my arrays which hold the secret Code is this Ok?
Second I have to initialize it but I'm not sure how.
PS I will put the instructions in the bottom in case some one can see what I'm doing wrong
This is what i have:
public class KeyPadLock {
private boolean isOpen; // true means lock is open; false means closed
private int[] secretCode = {2, 3, 4, 5,}; // the lock's code (a sequence of digits)
private int[] red; // most recently entered digits
private boolean match = true; // to compare if secretCode to red
public KeyPadLock(int[] code) {
          red = new int [code.length];
          int i = 0;
          while (i <= red.length){
          red[i] = code;
          i = i + 1;
/** Constructs a KeyPadLock object having the code specified by the
* parameter.
* @param code an array storing the constructed lock's code
* (i.e., the sequence of digits needed to open it), stored
* one digit per element.
* @pre for all i in range 0 .. code.length - 1, 0 <= code[i] < 10
* @post The newly-constructed lock has as its code the sequence of digits
* given by code[] and its "memory" of digits entered at the keypad
* indicates that no digits have ever been entered.
Edited by: dchjava on Oct 19, 2008 3:16 PM

Hi,
I have worked developing my KeyPadLock class, after talking to my Professor, I realized that in my constructor I have to initialize the secretCode array and the red array, which I did. I think! I also remove one of my declaration fields (the boolean match) since I don't really need it. The program is compiling, but I still have one error in one of my methods, which Opens the KeyPadLock, the problem is that I need to implement an if statement and I'm not sure how, could I get some help with this method:
public void open() { 
          int i = 0;
          while (i != secretCode.length && secretCode[i] == red) {
          i = i + 1;
          if (i = red.lenght){
          isOpen;
          else {}
Also, here is my whole class in case it helps:
public class KeyPadLock {
private boolean isOpen; // true means lock is open; false means closed
private int[] secretCode; // the lock's code (a sequence of digits)
private int[] red; // most recently entered digits
/* c o n s t r u c t o r s */
public KeyPadLock(int[] code) {
          secretCode = new int[code.length];
          int i = 0;
          while (i < secretCode.length){
          secretCode[i] = code[i];
          i = i + 1;
          red = new int[code.length];
          int i = 0;
          while (i < red.length){
          red[i] = code[i];
          i = i + 1;
/** Reports whether or not the lock is currently open.
* @pre none
* @return true if the lock is open, false otherwise
public boolean isOpen() {
          return isOpen;
/* m u t a t o r s */
/** Records the entering of a digit on the keypad.
* @pre 0 <= digit < 10
* @post If isOpen(), the digit entered is ignored.
* Otherwise it has been recorded as the latest digit entered
* on the keypad.
public void enterDigit(int digit) {
          red[i] = dgit;
          for (int i = 0; i != red.length-1; i++){
          red[i] = red[i + 1];
          red[red.lenght] = digit;
/** Attempt to open the lock.
* @pre none
* @post If the lock was already open or if the most recently entered
* digits match the lock's code, the lock is now open.
* Otherwise, it remains closed. Nothing else about the lock
* has changed.
public void open() { 
          int i = 0;
          while (i != secretCode.length && secretCode[i] == red[i]) {
          i = i + 1;
          if (i = red.lenght){
          isOpen;
          else {}
/** Close the lock.
* @pre none
* @post !isOpen(). Nothing else about the lock has changed.
public void close() {
          isOpen = false;

Similar Messages

  • One hell of a problem !!!!!!!!!!

    OK, so I just did the v4 upgrade using the software updater, all good. One problem, and its a doozy. I left my memory card in when I did the update (my brother did and it worked alright for him, although he later informed me he doesnt have much installed on there, whereas I do). Anyway, now every time I restart (or put the mem card back in), it says "Installing" for about 3 minutes while it tries to instll suff from the memory card. After that time it fails and says "Unable to install remaining applications, to install go to Application Manager".
    Problem #1 - I got to App. Manager (which take AGES to load), and it lists a whole heap of jibberish programs (like 20003cfb.sis and the like) which say "Not installed". 20003cfb.sis is the first in the list, I cant delete it so I try to install it. It asks me if I want to Install KeypadLock? I say yes. Bang, File Corrupted! So I thought I would format the mem card from the phone.
    Problem #2 - I copied everything on my card across to a folder on my PC with the intention of formatting the card. "Unable to format memory card, card in use by another application". (There is nothing running, I'm guessing the thing thats trying to install when I boot up is still running somewhere). So, I thought I would format on the PC using the card reader.
    Problem #3 - It does weird stuff here, it tells me the card capacity is 3.83GB (its 2GB), I try to go ahead anyway. No can do. Write protected. **bleep**?
    So I just manually delete everything using PC Suites File Manager. Its all gone now except a folder called "Data" (can't be deleted). Which has a sub folder called "NEF" in it, in there is a file called NEFConfig.xml and another folder called "Log". Thats it. Interestingly my Java progs are still showing up as installed in App manager (but they arent working). So I try to format again both ways.
    Problem #4 - Still nothing, cant do it. How do I stop it trying to install these non-existant programs?!
    Software updater never told me I ad to rmove my card which makes this all the more frustrating.
    I think that cvers everything Ive tried to date. Ive been at it a while now, any ideas would be appreciated.

    Its a bit of a pain but i would do a full factory reset of the phone.
    It will delete everything on your cards but at least you will start from a claen system.
    I don't think the backup tool is any good when you have upgraded so you will have to re-install everything from scratch. (at least syncronising contacts is easy!)
    At the end of all this your phone should be stable.
    to do a factory reset enter *#7370# into your phone.
    It will ask for your lock code (default is 12345)
    You could try manually putting things back together but the phone will probably object and you will end up doing this anyway!
    Nick.
    Phone List: (in order of appearance)
    Nokia 101 (remember them?), Ericsson 388, Nokia 7110, Ericsson t39, Sony Ericsson p800, Nokia N80, HTC TYTNII, HTC HD2, Nokia Lumia 920

  • N78 keypad issue

    Hi,
    I have bought a N78 few weeks ago and since the first time I used it I found a problem with keypad.
    Often, the press of the ANSWER key (green key) doesn't show the "dialled numbers" screen but it works as I had pressed the LEFT SELECTION KEY shortcut (that is over it).
    At the beginnind I thought to a hardware problem due to the keypad of my phone, but 'every time' that it happens if I "enable" and then "disable" the keypad-lock then the ANSWER key came back to work properly!!!, so I think it's a SOFTWARE bug because if it's a HW problem the keypadlock enable->disable trick shouldn't work every time! No?
    Is there someone who have the same problem?
    I tried also to update the firmware with FOTA to the v11.043.051.1 but without any results.

    yes mine has got the same button problem with the back button i am beginning to regret paying £300 now none of my software works ie garmin xt i down loaded laatest update as well media safe wont work eather i would have thought nokia would have made sure software backward compatable.i have had this now for 6 weeks i bought it from cpw sim free as i use 02 simplis card,this is my 4th one now all with button problems cpw say that i cant change it again as its my 4th one i would have to have it repaired i am not bothered about getting it repaired but i dont think they have a fix for the button problem yet so what the use of sending it in till i see on hear that there is a fix.i realey like this phone it would be a keeper for me i only hope they come up with an answer for the button and 3rd party soft ware compatibly.dose anyone else have garmin xt working on n78 i would love to know if there is a fix.(COME ON NOKIA WHATS WRONG WITH THE BUTTONS IS IT A SOFTWARE OR HARDWARE FIX)Nokia n78 Firmware is V11.043
    Message Edited by skanska on 08-Jul-2008 05:21 PM

  • E65 smart2go and other utils..

    I just bought an E65 and I'm very pleased with the phone this far. I've started to look at different extra software for it and I've installed Mail for Exchange (works great!) and also the GMail mail app which also works great. I've tried Fring to make a Skype call over a WLAN connection , not that great sound quality though the chat function worked just fine!
    I own a bluetooth GPS and it seems like the E65 can connect to it and I've been thinking about GPS software for it.
    Smart2go is a tempting solution, but E65 is not listed as a compatible phone and I've seen some entries in this forum suggesting there is a problem with that setup on the E65. Can anyone confirm that they have got smart2go working with predownloaded maps on the E65 even if Smart2go officially won't support it?
    I also lack one feature in the E65 and that is a keypadlock that won't unlock the keypad just because the slider is opened. I've history of repeated outgoing "pocket calls" with previous phones and need a way of making sure accidental calls are not going to occur. Have any tried any of the lock applications avaible in the catalogue? Handylock and so on (whatever they are called).
    Will the app require an unlock keysequence in addition to the slider being opened?

    Another way around with the keylock that doesn't need any separate application to be installed...
    Use the built in lock function under security options. Can be configured to lock after a period of time and if you want to lock the phone immediately press the power button once and select lock phone. Note ! Option only available after you have configured the security code.

Maybe you are looking for

  • Prepping a Sequence for Web/and EXporT

    Any link or answer to this- i'm preparing a 2 minute trailer for web. what are the settings necessary in final cut to prepare for the quicktime export. Also once in a quicktime format what should the export settings coming out. currently have final c

  • Access variable in the same tilme

    Can i have to access in reading at the same time (for example by 2 process in parallel) at a control (string for example) witout risk to crash the PC? Likewise, is it possible to write at the same time in a indicator  witout risk to crash the PC? How

  • Poor Image Quality at Start Menu

    Hi All I use iDVD 08 for my movies and was creating a menu at the start of the program. While the resolution looks good in iDVD (before burning to DVD), it is not so after. I would like to enquire on how can can improve on the image quality on my DVD

  • SQL HELP , URGENT PLEASE

    Hi, I want some help in writing a SQL Query .Its besically a hierarchical query. Let me lay down the table structure first to explain my requirements better. PORP_TABLE(NODE_LEVEL int, WBS_ID int, WBS_NUMBER varchar(60), LFT int,RGT int) SELECT NODE_

  • Streams Instantiation Table don't execute

    Hi. I am trying execute the following command in my streams environment and it give me no response, no conclusion. I declare source_scn number; begin source_scn := dbms_flashback.get_system_change_number(); dbms_apply_adm.set_table_instantiation_scn@