• Post Reply Bookmark Topic Watch Topic
  • New Topic

Sudoku program compilation error - goodsubsquare method  RSS feed

 
Leon Tee
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey! So i finished writing out the methods to my sudoku program but im still getting a few errors and I'm not sure how to proceed

Here is the program and I have and the issue is with the good sub square method




and when i run it with a driver class i get



Any help? I'm lost on figuring out where I went wrong but i suspect it has to do with the goodSubsquare method
 
Leon Tee
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Also this

the first one says: incompatible types, int cannot be converted to i

second one says identifier expected
 
Dave Tolls
Ranch Foreman
Posts: 3056
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the definition of your colIsLatin method.
In that one you have given your parameters a type (an array and an int).

If you look at the method causing the compilation problem (note, there's no point running code that doesn't compile) you should now see what is missing.
 
Liutauras Vilda
Sheriff
Posts: 4916
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are the data types of i and j? All parameters need to have explicitly specified their data types.
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tell us what the error messages are when you hover the mouse over the red marks on the IDE. I think you have got {} not correctly matched, and the wrong numbers of arguments to match method calls.
You also appear to have things marked public which are only required inside the Sudoku class, and shoul‍d maybe be private.
Why have you got the arrays as String[][]s rather than numbers?
Your single‑letter variables are hard to understand. It makes the entire logic of your program difficult to follow.
 
Leon Tee
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:Look at the definition of your colIsLatin method.
In that one you have given your parameters a type (an array and an int).

If you look at the method causing the compilation problem (note, there's no point running code that doesn't compile) you should now see what is missing.


Okay so I see that in my colIsLatin method I have given the parameters type array and type int

looking at the goodSubsquare method , do i need to add thef data type to those parameters  as well?
 
Leon Tee
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Tell us what the error messages are when you hover the mouse over the red marks on the IDE. I think you have got {} not correctly matched, and the wrong numbers of arguments to match method calls.
You also appear to have things marked public which are only required inside the Sudoku class, and shoul‍d maybe be private.
Why have you got the arrays as String[][]s rather than numbers?
Your single‑letter variables are hard to understand. It makes the entire logic of your program difficult to follow.





I had them as string because i was assuming that i would be storing strings of sudoku text in them

Which ones should I make private? Sorry for all the questions
 
Leon Tee
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:Look at the definition of your colIsLatin method.
In that one you have given your parameters a type (an array and an int).

If you look at the method causing the compilation problem (note, there's no point running code that doesn't compile) you should now see what is missing.


ahhh i see now what the issue was. I feel so stupid lol
 
Leon Tee
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Tell us what the error messages are when you hover the mouse over the red marks on the IDE. I think you have got {} not correctly matched, and the wrong numbers of arguments to match method calls.
You also appear to have things marked public which are only required inside the Sudoku class, and shoul‍d maybe be private.
Why have you got the arrays as String[][]s rather than numbers?
Your single‑letter variables are hard to understand. It makes the entire logic of your program difficult to follow.


I found the error to the program.

However is there anything you can recommend for a cleaner easier to follow program in the future?
 
Dave Tolls
Ranch Foreman
Posts: 3056
37
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Leon Tee wrote:
Okay so I see that in my colIsLatin method I have given the parameters type array and type int

looking at the goodSubsquare method , do i need to add thef data type to those parameters  as well?


I would assume your notes would have told you what the basic format of a method was...but yes, your parameters need to be given a type.
 
Leon Tee
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:
Leon Tee wrote:
Okay so I see that in my colIsLatin method I have given the parameters type array and type int

looking at the goodSubsquare method , do i need to add thef data type to those parameters  as well?


I would assume your notes would have told you what the basic format of a method was...but yes, your parameters need to be given a type.



yeah it was a brain goof by me. I promise I'm not usually this dense. Thank you for your help
 
Dave Tolls
Ranch Foreman
Posts: 3056
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Leon Tee wrote:[
yeah it was a brain goof by me. I promise I'm not usually this dense. Thank you for your help


We all have those moments.
Code blindness.
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Leon Tee wrote:. . . Which ones should I make private? Sorry for all the questions
No problem about lots of questions; that is what you are here for.
Make all field private. Also all methods except the main method. See whether you can persuade your code to compile; you can always remove the private modifier if necessary.
Why have you got those two nested classes?
 
Junilu Lacar
Sheriff
Posts: 11477
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Leon Tee wrote:However is there anything you can recommend for a cleaner easier to follow program in the future?


Well, here are some things about your program that I suggest you think about more carefully:

1. What does a row or column being Latin have anything to do with Sudoku?
2. The methods named rowIsLatin() and rowsAreLatin() are obviously related but the names are too similar to each other
3. Same issue as #2 with the methods named colIsLatin() and colsAreLatin()
4. Why use Strings when the elements in a Sudoku puzzle are numbers?
5. The methods goodSubsquare() and goodSubsquares() only have one letter difference in their names. It's easy to miss that extra "s" at the end.
6. What in the world are the static classes at the end there for? Why are they named like variables?
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junilu Lacar wrote:. . . What in the world are the static classes at the end there for? Why are they named like variables?
Maybe, because there was a compiler error and one of the quick‑fix suggestions is, “create nested class i”.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!