Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Phase 1: The board First, implement the abstract class Tile. This class represen

ID: 3724540 • Letter: P

Question

Phase 1: The board First, implement the abstract class Tile. This class represents the elements of the two-dimensional array that is the board (a Tile[][] array). The tiles will hold the game pieces or a wall. We will add more to this class later. To start, a Tile should have: Two instance variables: a String which is the symbol that should be displayed by this tile,and a boolean which will indicate if this tile is a tile that the player can move onto (is “passable”). A constructor that has two parameters – the String and the boolean, in that order. Method String getSymbol()which fetches the symbol that should be displayed. Method boolean isPassable() which indicates if the tile is passable.


Now implement two subclasses of the Tile class: Wall, and OpenSpace.

Class Wall is not passable, and the symbol is a hash:#

Class OpenSpace is an empty space which is passable, and the symbol is a period: .

These subclasses will only contain constructors. All the other logic in them is inherited from class Tile.

You can test your classes using the supplied test program TestPhase1.java. You should get the output shown below.

####

#..#

#..#

####

Explanation / Answer

public class Tile { // Starting the class 'Tile'

public String symbol; // Declaration of instance variable symbol
public boolean passableFlag; // Declaration of instance variable passableFlag

Tile(String symb, boolean passflag) { // Constructor with two parameters: string and boolean
this.symbol = symb; // Assigning the parameters passed in the constructor to instance variables
this.passableFlag=passflag;
}
public void getSymbol(){ // Declaration of method getSymbol()

System.out.println(symbol); // Printing the variable symbol

public void isPassable(){ // Declaration of method isPassable()
if(passableFlag = 1) { // Checking the flag if it is true
System.out.println("It is passable"); // Printing "It is passable"
}else {  
System.out.println("It is not passable"); // Printing "It is not passable"
}

}

public class Wall extends Tile{ // Declaring a Sub class 'Wall'
Wall() {
this.symbol = "#"; // Assigning the given values
this.passableFlag=0;
}

public class OpenSpace extends Tile{ // Declaring a Sub class 'OpenSpace'
OpenSpace() {
this.symbol = "."; // Assigning the given values
this.passableFlag=1;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote