Question
Complete Java code and its explanation, gets thumbs up and much appreciation. Please explain how to write a class called Piece that: Piece a class
Complete Java code and its explanation, gets thumbs up and much appreciation.
Please explain how to write a class called Piece that:
Piece a class to represent chess pieces (Some people distinguish between pawns and pieces, well call pawns pieces as well.) Piece should be abstract and
have the following constructors and methods:
a public constructor that takes a Color parameter and stores its value in an instance variable
a public getColor() instance method that returns the Color of the piece
a public abstract instance method algebraicName() which returns a String containing the algebraic name of the piece, e.g., "" for pawns, or one of "K", "Q", "B", "N", "R" .
a public abstract instance method fenName() which returns a String containing the name for the piece according to FEN notation which can be found here http://www.saremba.de/chessgml/standards/pgn/pgn- complete.htm#c16.1 .
a public abstract instance method movesFrom(Square square) which returns a Square[] containg all the squares the piece could move to from square on a chess board containing only the piece.
A subclass of Piece named King which overrides Piece s abstract methods appropriately A subclass of Piece named Queen which overrides Piece s abstract methods appropriately A subclass of Piece named Bishop which overrides Piece s abstract methods appropriately A subclass of Piece named Knight which overrides Piece s abstract methods appropriately A subclass of Piece named Rook which overrides Piece s abstract methods appropriately A subclass of Piece named Pawn which overrides Piece s abstract methods appropriately
Add descriptions of how the the classes function, and they will be tested by for example: (Stub methods so that all classes compile and return values, as most of Piece and its subclasses will be checked in isolation)
Piece knight = new Knight(Color.BLACK); assert knight.algebraicName().equals("N"); assert knight.fenName().equals("n"); Square[] attackedSquares = knight.movesFrom(new Square("f6")); // test that attackedSquares contains e8, g8, etc.
Square a1 = new Square("a1"); Square otherA1 = new Square('a', '1'); Square h8 = new Square("h8"); assert a1.equals(otherA1); assert !a1.equals(h8);
Piece -a class to represent chess pieces (Some people distinguish between pawns and pieces, we'll call pawns pieces as well.) Piece should be abstract and have the following constructors and methods: a public constructor that takes a color parameter and stores its value in an instance variable o a public getColor) instance method that returns the Color of the piece o a public abstract instance method algebraicName() which returns a String containing the algebraic name of the piece, e.g., "" for pawns, or one of o a public abstract instance method fenName() which returns a String containing the FEN name for the piece. o a public abstract instance method movesFrom (Square square) which returns a Square[ containg all the squares the piece could move to from square on a chess board containing only the piece. . A subclass of Piece named King which overrides Piece 's abstract methods appropriately A subclass of Piece named Queen which overrides Piece 's abstract methods appropriately A subclass of Piece named Bishop which overrides Piece 's abstract methods appropriately A subclass of Piece named Knight which overrides Piece 's abstract methods appropriately A subclass of Piece named Rook which overrides Piece 's abstract methods appropriately A subclass of Piece named Pawn which overrides Piece 's abstract methods appropriatelyStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started