Question: Using Java to create the following classes below. Create a parent class called ChessPiece . Then create child classes called Pawn , Knight , Bishop

Using Java to create the following classes below.

Create a parent class called ChessPiece. Then create child classes called Pawn, Knight, Bishop, Rook, Queen, and King.

The ChessPiece class has an instance variable for color (a boolean: white?) and value (an int), indicating how important it is, which is set by the constructor parameter. It also has an accessor method for it, called getValue(). The value of each class is:

Pawn 1

Knight 2

Bishop 3

Rook 5

Queen 9

King 1000

This class also has a method called move() which actually does nothing but System.out.println(moving).

The ChessPiece class overrides the toString() method and returns the name of its class (e.g. White Pawn or Black Knight, etc).

Each of the six ChessPiece subclasses further overrides the toString() method and returns the name of its class in addition to its value (e.g. White Pawn(1) or Black Knight(2), etc). Note: use a super call to the parents toString() method! Each of the six ChessPiece subclasses also overrides the move() method, to System.out.println() how this particular piece moves:

Pawn forward 1

Knight like an L

Bishop diagonally

Rook horizontally or vertically

Queen like a bishop or a rook

King one square

Note: Use the @Override annotation every time you override a method.

Main

Create a class called Main with a main() method that sets up a chessboard on a two-dimensional array of Pieces:

https://en.wikipedia.org/wiki/Chess#Setup

The main() method loops through the board and prints each piece (thus triggering its toString() method).

Please follow the instructions above for a good rate

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!