I'm trying to implement a toString method, and the output of the toString depends on the boolean variables. Below is my class and main.
public class Cell {
public int addSpaces;
boolean isEmpty;
boolean isChute;
boolean isLadder;
public Cell() {
addSpaces = 10; //I initialized addSpaces to 10 for testing purpose
}
public boolean isChute() { //first boolean method
if (addSpaces == -10) {
return true;
} else {
return false;
}
}
public boolean isLadder() {//second boolean method
if (addSpaces == 10) {
return true;
} else {
return false;
}
}
public boolean isEmpty() { //third boolean method
if (addSpaces == 0) {
return true;
} else {
return false;
}
}
public String toString() {
String print;
if (isChute = true) //if isChute is true return true.
{
print = "C10"; // toString output = "C10"
} else if (isLadder = true) // if isLadder is true return true
{
print = "L10"; // toString output == "L10"
} else {
print = "---"; // else toString print output = "---"
}
return print;
}
public static void main(String[] arg) {
Cell s = new Cell();
System.out.println(s.addSpaces);
System.out.println(s);
}
}
Regardless of the input state of toString, I basically get the same output "C10".
Can someone tell me what I did wrong?
I'm new to this website so I appreciate any feedback for future reference. Thank you.