i established an array of objects. i want to user to name a chess piece, the name of the chesspiece then will search the object in the array
package il.co.ChessInterface;
import il.co.Pawn.Pawn;
import il.co.Bishop.*;
import il.co.King.*;
import il.co.Queen.*;
import il.co.Rook.*;
import il.co.Knight.*;
import java.io.Console;
public class ChessInterface {
public static void main(String[] arg){
Console console=System.console();
String chessPiece="";
int rowStart = 0;
char columnStart = 0;
int i;
System.out.println("what piece do you want to move?");
chessPiece=console.readLine();
System.out.println("where do you want to move it to?(type column letter)");
String input=console.readLine(); // the name of the chess piece is entered "e.g. "Bpn1""
char columnEnd=input.charAt(0);
System.out.println("where do you want to move it to?(type row number)");
int rowEnd=Integer.parseInt(console.readLine());
ChessPiece pieces[][];
pieces =new ChessPiece[7][7];
pieces[1][0]=new Pawn("Bpn1");// this should be searched and found.
pieces[1][1]=new Pawn("Bpn2");
pieces[1][2]=new Pawn("Bpn3");
pieces[1][3]=new Pawn("Bpn4");
pieces[1][4]=new Pawn("Bpn5");
pieces[1][5]=new Pawn("Bpn6");
pieces[1][6]=new Pawn("Bpn7");
pieces[1][7]=new Pawn("Bpn8");
pieces [0][0]=new Rook("BR1");
pieces [0][1]=new Knight("BN2");
pieces [0][2]=new Bishop("BB3");
pieces [0][3]=new King("BR4");
pieces [0][4]=new Queen("BQ5");;
pieces [0][5]=new Bishop("BB6");
pieces [0][6]=new Knight("BN7");
pieces [0][7]=new Rook("BR8");
could something like that work:
for(Object x:pieces){
if(x==chessPiece)
System.out.println("__ "+"|");
all the pieces are located in different classes that arent presented here