Question: Change this code from C ++ to Java. re-write the code in JAVA 1 // main.cpp 2 #include 3 #include board.h 4 #include piece.h 5

Change this code from C ++ to Java. Change this code from C ++ to Java. re-write the code in

JAVA 1 // main.cpp 2 #include 3 #include "board.h" 4 #include "piece.h"

5 #include "pawn.h" 6 using namespace std; 8 int main() 9{ 10

const int x = 4; const int Y = 4; Board board

= new Board; Piece *piece; cout display(); 20 21 piece = new

Pawn (X, Y, board); piece->insert(); cout display(); delete piece; delete board; return

0; 22 23 247 abole in JAUR. re-write the code in Java

re-write the code in JAVA 1 // main.cpp 2 #include 3 #include "board.h" 4 #include "piece.h" 5 #include "pawn.h" 6 using namespace std; 8 int main() 9{ 10 const int x = 4; const int Y = 4; Board board = new Board; Piece *piece; cout display(); 20 21 piece = new Pawn (X, Y, board); piece->insert(); cout display(); delete piece; delete board; return 0; 22 23 247 abole in JAUR. re-write the code in Java 1 // board.h 2 #ifndef BOARD_H // include guard 3 #define BOARD_H 5 class Board { 6 private: 7 static const int SIZE = 8; 8 static const char WHITE = ''; 9 static const char BLACK - '#'; 10 char slot[SIZE][SIZE); 11 public: Board(); 13 void line(); 14 void display(); 15 bool validate(int x1, int yi); 16 void setslot(int x, int y, charc); 17); 18 #endif 12 re-write the code In Java // board.cpp sinclude Binclude "board.h" " Board:: Board() { inty - e; forty.0; y 7)) return false; return true; 50 void Board::setslot(int x, inty, charc) { if (validate(x, y)) slot[x][y]. 1 // piece.h 2 #ifndef PIECE_H // include guard 3 #define PIECE_H 4 #include "board.h" AM2 in Java re-write the code in yaua 6 class Piece { 7 protected: int x; 9 int y; 10 Board *b; char symbol; 12public: 13 Piece(int x, inty, Board "b); virtual void insert() = 0; 15); | Hendif Piece it intx, It inty; 1 // pawn.cpp 2 #include "pawn.h" Att in your re-write the code - In Java 4 void Pawn::insert() { $ if (b->validate(x,y)) { if (y != 0) b->setslot(x, y, 'P'); else // future section for Queen char move; if ((y+1 != 1)) move - i++) else move - 'Q'; for(int x1 = (x-1); x1 set Slot(x1, (y-1), move); if (y = 6) b->set Slot(x, (y-2), ); thi 1 // pawn.h 2 #ifndef PAWN_H // include guard 3 #define PAWN_H 4 #include "piece.h" in JAUR re-write the code in yava 6 class Pawn : public Piece { 7 public: 8 Pawn(int x, inty, Board "b) : Piece(x, y, b) () 9 void insert(); 10); Il sendif t in Java re-write 1// piece.cpp 2#include "piece.h" the code 4Piece::Piece(int x, inty, Board *b) { this->X - X; this->y - y this-> = b; in Java

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!