By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,262 Members | 1,128 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,262 IT Pros & Developers. It's quick & easy.

help placing rocks in a grid

P: 2
Can someone help me with what i am missing in this code. I can't get it to compile. Thx!
Expand|Select|Wrap|Line Numbers
  1. import javax.swing.*;
  2.  
  3. public class PlaceRocks
  4. {
  5.  
  6. private static final int GRID_SIZE = 3;
  7.     private static final String ROW_PROMPT = "Enter a row from: 0, 1, 2";
  8.     private static final String COLUMN_PROMPT =
  9. "Enter a column from: 0, 1, 2";
  10.     private static final String DENIED = "This row/column is already taken.";
  11.     private static final String ACCEPTED = "Done.";
  12.  
  13.  
  14.     public static void main(String[] s)
  15. {
  16.         boolean[] columns = new boolean[GRID_SIZE];
  17.         boolean[] rows = new boolean[GRID_SIZE];
  18.  
  19.  
  20. for(int j = 0; j < 3; j++)
  21. {
  22. String inputRow = JOptionPane.showInputDialog(ROW_PROMPT);
  23.             int rowNumber = Integer.parseInt(inputRow);
  24.  
  25. String inputColumn = JOptionPane.showInputDialog(COLUMN_PROMPT);
  26.             int columnNumber = Integer.parseInt(inputColumn);
  27.  
  28.             if (isCellTaken(rowNumber, columnNumber,
  29.     rows, columns))
  30. {
  31.     JOptionPane.showMessageDialog(null, DENIED);
  32.             }
  33.             else
  34. {
  35.     rows[rowNumber] = true;
  36.     columns[columnNumber] = true;
  37.     JOptionPane.showMessageDialog(null, ACCEPTED);
  38.             }
  39.         }
  40.     }
  41.  
  42.  
  43.     private static boolean isCellTaken(rows, columns, row, column)
  44. {
  45.         if(rows[row] && columns[column])
  46. {
  47.             return true;
  48.         }
  49.         else
  50. {
  51. return false;
  52. }
  53.  
  54. }
  55.  
  56. }
May 30 '07 #1
Share this Question
Share on Google+
3 Replies


Expert 10K+
P: 11,448
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
May 30 '07 #2

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

Tool completed with exit code 1
May 30 '07 #3

Expert 10K+
P: 11,448
Your curly brackets and/or parentheses aren't balanced; check them all.

kind regards,

Jos
May 30 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.