Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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);

image text in transcribed

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 appropriately

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke

4th Edition

0136086535, 9780136086536

More Books

Students also viewed these Databases questions

Question

How do modern Dashboards differ from earlier implementations?

Answered: 1 week ago