Good to have you back!
D.J. Quavern wrote:I wrote all in Java and tried to do all in a Javanic way
I'm afraid that apart from the syntax and the classes from the standard API, there's not much 'Javanic' about your code. Why is everything in the main method? Why have you not split up your application in separate classes that are responsible for different things? Why are you using poor variable names like fB
First, I suggest you rewrite the application so that you have a Position
class that encapsulates the coordinates on a chessboard, a Diagonal
class that can tell you the positions of the squares that are on the diagonal it represents, and a Bishop
class that encapsulates a position and can determine in how many moves it can reach another specified position. Then, in your main class add a method that reads a position from the standard input. Call it twice and construct a bishop of one of them. Let the bishop determine how many moves it needs to reach the other position.
Now that you have different classes and methods, you can write proper unit tests that will tell you in what part of the code the problem lies.
Before you implement any methods, write some skeleton classes and show it to us so we can tell you you are on the right track. For instance, you can add a method getColor()
to the Position
class, but don't implement it yet.
I even closed the scanner.
You managed to do it at the one time you shouldn't have: don't close System.in
or resources based on System.in
. Also, when you do want to close a resource, do it by using the try-with-resources