Results 1 to 5 of 5
  1. #1
    lannie1980 is offline Member
    Join Date
    Mar 2012
    Posts
    88
    Rep Power
    0

    Default Looking for help with program please - newbie programmer ;)

    Hey all,

    I'm new to Java and I'm currently studying it in my spare time. I have a code question that I just can't seem to figure out and hopefully some of the more experienced folks on here can lend a hand.

    I'm coding a wordsearch puzzle and I need to write a helper method called isHorizontalSpaceFree()

    The method should check whether(starting from aRow and aCol) there is enough free space to insert word into letterGrid(left to right). If there is enough space, the method should return true, otherwise it should return false.

    I need the method to return an out of bounds exception if the word length exceeds the end of the array as well.

    Here is my code so far

    public boolean isHorizontalSpaceFree(int aRow, int aCol, String word)
    {
    boolean result = true;
    if (aCol < NUMBER_COLS - word.length())
    {
    int i = aCol;
    while (aCol < NUMBER_COLS - word.length())
    {
    if (letterGrid[aRow][aCol] != BLANK_ELEMENT
    || aCol > NUMBER_COLS - word.length())
    {
    result = false;
    }
    aCol++;
    }
    }
    else
    {
    result = false;
    }
    return result;
    }

    I hope it's not too far away lol

    Thanks in advance

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,802
    Rep Power
    19

    Default Re: Looking for help with program please - newbie programmer ;)

    Please use [code] tags [/code] when posting code.
    What does that code do that it shouldn't?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    lannie1980 is offline Member
    Join Date
    Mar 2012
    Posts
    88
    Rep Power
    0

    Default Re: Looking for help with program please - newbie programmer ;)

    Hi and thanks for the quick respons. I will adhere to the code posting rules from now on - thanks for the pointer ;)

    I'm looking at the code and all I can possibly say is that initialising int i = aCol might be wrong.
    I think it may be something wrong with the logic or the if conditions though and this is what I can't work out.
    Any futher light shed and help is really appreciated here.

    Thanks

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,802
    Rep Power
    19

    Default Re: Looking for help with program please - newbie programmer ;)

    You haven't said what it's doing that it shouldn't, though.
    Stick some println()s in there so you can see what's happening inside that code.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    lannie1980 is offline Member
    Join Date
    Mar 2012
    Posts
    88
    Rep Power
    0

    Default Re: Looking for help with program please - newbie programmer ;)

    Hi again,

    I put in some println()s and it appears to be processing the whole array up to NUMBER_COLS - word.length(). What I need it to do is to check that there is enough space for the word to fit i.e there are enough BLANK_ELEMENT in a row to accomodate the word.length() and for the program to return false if it hits a char() or exceeds the array boundary.

    I'm still puzzled lol ;(

    Thanks

Similar Threads

  1. Newbie needs help with program assignment
    By pitmanr2003 in forum New To Java
    Replies: 3
    Last Post: 02-25-2012, 05:45 PM
  2. Gradebook Program... Newbie
    By java_beaner in forum New To Java
    Replies: 2
    Last Post: 09-24-2011, 07:55 PM
  3. Newbie here with first database program
    By Jstn455 in forum JDBC
    Replies: 2
    Last Post: 03-16-2011, 02:51 AM
  4. Replies: 6
    Last Post: 12-17-2008, 03:37 PM
  5. Help with my first program...newbie
    By giganews35 in forum New To Java
    Replies: 6
    Last Post: 12-01-2008, 07:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •