I searched a lot for this but couldn't find it anywhere, but if you think that it had been asked before, please send me the link.
I have a parent class called chesspiece and I have 6 child classes: Pawn with the value of 1, Knight with the value of 2, Bishop with the value of 3, Rook with the value of 5, Queen with the value of 9 and king with the value of 1000.
I have two instance variable: value and the color of the piece
I want to know is it possible to say if you have the value of 1 you belong to the pawn class or if you have the value of 2, you belong to the knight class. So, right now I'm doing this using a method but it only returns a String and nothing more. Here's my code:
public class ChessPiece {
private boolean isWhite;
private int value;
public ChessPiece (boolean isWhite, int value) {
this.isWhite = isWhite;
this.value = value;
}
public String getNamebyValue() {
switch (value) {
case 1:
return "Pawn";
case 2:
return "Knight";
case 3:
return "Bishop";
case 5:
return "Rook";
case 9:
return "Queen";
case 1000:
return "King";
}
return null;
}
And here's my child class:
public class Bishop extends ChessPiece {
public Bishop(boolean isWhite) {
super(isWhite, 3);
}