help placing rocks in a grid

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • coderAmy
    New Member
    • May 2007
    • 2

    help placing rocks in a grid

    Can someone help me with what i am missing in this code. I can't get it to compile. Thx!
    [code=java]
    import javax.swing.*;

    public class PlaceRocks
    {

    private static final int GRID_SIZE = 3;
    private static final String ROW_PROMPT = "Enter a row from: 0, 1, 2";
    private static final String COLUMN_PROMPT =
    "Enter a column from: 0, 1, 2";
    private static final String DENIED = "This row/column is already taken.";
    private static final String ACCEPTED = "Done.";


    public static void main(String[] s)
    {
    boolean[] columns = new boolean[GRID_SIZE];
    boolean[] rows = new boolean[GRID_SIZE];


    for(int j = 0; j < 3; j++)
    {
    String inputRow = JOptionPane.sho wInputDialog(RO W_PROMPT);
    int rowNumber = Integer.parseIn t(inputRow);

    String inputColumn = JOptionPane.sho wInputDialog(CO LUMN_PROMPT);
    int columnNumber = Integer.parseIn t(inputColumn);

    if (isCellTaken(ro wNumber, columnNumber,
    rows, columns))
    {
    JOptionPane.sho wMessageDialog( null, DENIED);
    }
    else
    {
    rows[rowNumber] = true;
    columns[columnNumber] = true;
    JOptionPane.sho wMessageDialog( null, ACCEPTED);
    }
    }
    }


    private static boolean isCellTaken(row s, columns, row, column)
    {
    if(rows[row] && columns[column])
    {
    return true;
    }
    else
    {
    return false;
    }

    }

    }[/code]
    Last edited by JosAH; May 30 '07, 02:29 PM. Reason: added [code] ... [/code] tags
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by coderAmy
    Can someone help me with what i am missing in this code. I can't get it to compile. Thx!
    The compiler must've spewed out a bit more than "I can't compile this". Copy
    and paste the compiler diagnostic message(s) here and we'll see if we can help.

    kind regards,

    Jos

    Comment

    • coderAmy
      New Member
      • May 2007
      • 2

      #3
      D:\Documents and Settings\amy.as her\My Documents\ICS 141\PlaceRocks. java:43: <identifier> expected
      private static boolean isCellTaken(row s, columns, row, column)
      ^
      D:\Documents and Settings\amy.as her\My Documents\ICS 141\PlaceRocks. java:54: ')' expected
      }
      ^
      D:\Documents and Settings\amy.as her\My Documents\ICS 141\PlaceRocks. java:43: cannot resolve symbol
      symbol : class rows
      location: class PlaceRocks
      private static boolean isCellTaken(row s, columns, row, column)
      ^
      D:\Documents and Settings\amy.as her\My Documents\ICS 141\PlaceRocks. java:28: isCellTaken(row s) in PlaceRocks cannot be applied to (int,int,boolea n[],boolean[])
      if (isCellTaken(ro wNumber, columnNumber,
      ^
      D:\Documents and Settings\amy.as her\My Documents\ICS 141\PlaceRocks. java:43: missing method body, or declare abstract
      private static boolean isCellTaken(row s, columns, row, column)
      ^
      5 errors

      Tool completed with exit code 1

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Your curly brackets and/or parentheses aren't balanced; check them all.

        kind regards,

        Jos

        Comment

        Working...