Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Big Data Systems A 360-degree Approach

Authors: Jawwad ShamsiMuhammad Khojaye

1st Edition

0429531575, 9780429531576

More Books

Students also viewed these Databases questions

Question

What are Decision Trees?

Answered: 1 week ago

Question

What is meant by the Term Glass Ceiling?

Answered: 1 week ago