Below are BooleanCompareNode.java, VariableReferenceNode.java, IfNode.java, RepeatNode.java, & WhileNode.java. Attached is an image where it's circled in blue all the methods that must be implemented in the java files that are presented below: BooleanCompareNode.java public class BooleanCompareNode extends Node { enum CompareType { eq, ne, lt, gt, le, ge }; CompareType type; Node left; Node right; public BooleanCompareNode(CompareType type, Node left, Node right) { this.type = type; this.left = left; this.right = right; } public String ToString() { return left.toString() + type.toString() + right.toString(); } } VariableReferenceNode.java public class VariableReferenceNode extends Node{ String name; Node arrayIndex; public VariableReferenceNode(String name) { this.name = name; this.arrayIndex = arrayIndex; } public String ToString() { String indexString = (arrayIndex == null) ? "" : "[" + arrayIndex.toString() + "]"; return name + indexString; } public void setIndex(Node indexExpr) { } public String getVariableName() { return null; } } IfNode.java import java.util.ArrayList; import java.util.List; public class IfNode extends Node{ private BooleanCompare condition; private ArrayList statements; private IfNode nextIf; public IfNode(BooleanCompare condition, ArrayList statements, IfNode nextIf) { this.condition = condition; this.statements = statements; this.nextIf = nextIf; } public BooleanCompare getCondition() { return condition; } public ArrayList getStatements() { return statements; } public IfNode getNextIf() { return nextIf; } @Override public String ToString() { StringBuilder sb = new StringBuilder("IfNode: { Condition: "); sb.append(condition.toString()).append(", Statements: ["); for (StatementNode statement : statements) { sb.append(statement.toString()).append(", "); } sb.delete(sb.length() - 2, sb.length()); sb.append("]"); if (nextIf != null) { sb.append(", NextIf: ").append(nextIf.toString()); } sb.append("}"); return sb.toString(); } } RepeatNode.java import java.util.ArrayList; public class RepeatNode extends Node { private BooleanCompare condition; private ArrayList statements; public RepeatNode(BooleanCompare condition, ArrayList statements) { this.condition = condition; this.statements = statements; } BooleanCompare getCondition() { return condition; } public ArrayList getStatements() { return statements; } @Override public String ToString() { StringBuilder sb = new StringBuilder("RepeatNode: { Condition: "); sb.append(condition.toString()).append(", Statements: ["); for (StatementNode statement : statements) { sb.append(statement.toString()).append(", "); } sb.delete(sb.length() - 2, sb.length()); sb.append("]}"); return sb.toString(); } } WhileNode.java import java.util.ArrayList; public class WhileNode extends Node { private BooleanCompare condition; private ArrayList statements; public WhileNode(BooleanCompare condition, ArrayList statements) { this.condition = condition; this.statements = statements; } public BooleanCompare getCondition() { return condition; } public ArrayList getStatements() { return statements; } @Override public String ToString() { StringBuilder sb = new StringBuilder("WhileNode: { Condition: "); sb.append(condition.toString()).append(", Statements: ["); for (StatementNode statement : statements) { sb.append(statement.toString()).append(", "); } sb.delete(sb.length() - 2, sb.length()); sb.append("]}"); return sb.toString(); } }
Java
BooleanCompareNode.java
public class BooleanCompareNode extends Node {
enum CompareType {
eq, ne, lt, gt, le, ge
};
CompareType type;
Node left;
Node right;
public BooleanCompareNode(CompareType type, Node left, Node right) {
this.type = type;
this.left = left;
this.right = right;
}
public String ToString() {
return left.toString() + type.toString() + right.toString();
}
}
VariableReferenceNode.java
public class VariableReferenceNode extends Node{
String name;
Node arrayIndex;
public VariableReferenceNode(String name) {
this.name = name;
this.arrayIndex = arrayIndex;
}
public String ToString() {
String indexString = (arrayIndex == null) ? "" : "[" + arrayIndex.toString() + "]";
return name + indexString;
}
public void setIndex(Node indexExpr) {
}
public String getVariableName() {
return null;
}
}
IfNode.java
import java.util.ArrayList;
import java.util.List;
public class IfNode<BooleanCompare> extends Node{
private BooleanCompare condition;
private ArrayList<StatementNode> statements;
private IfNode nextIf;
public IfNode(BooleanCompare condition, ArrayList<StatementNode> statements, IfNode nextIf) {
this.condition = condition;
this.statements = statements;
this.nextIf = nextIf;
}
public BooleanCompare getCondition() {
return condition;
}
public ArrayList<StatementNode> getStatements() {
return statements;
}
public IfNode getNextIf() {
return nextIf;
}
@Override
public String ToString() {
StringBuilder sb = new StringBuilder("IfNode: { Condition: ");
sb.append(condition.toString()).append(", Statements: [");
for (StatementNode statement : statements) {
sb.append(statement.toString()).append(", ");
}
sb.delete(sb.length() - 2, sb.length());
sb.append("]");
if (nextIf != null) {
sb.append(", NextIf: ").append(nextIf.toString());
}
sb.append("}");
return sb.toString();
}
}
RepeatNode.java
import java.util.ArrayList;
public class RepeatNode<BooleanCompare> extends Node {
private BooleanCompare condition;
private ArrayList<StatementNode> statements;
public RepeatNode(BooleanCompare condition, ArrayList<StatementNode> statements) {
this.condition = condition;
this.statements = statements;
}
BooleanCompare getCondition() {
return condition;
}
public ArrayList<StatementNode> getStatements() {
return statements;
}
@Override
public String ToString() {
StringBuilder sb = new StringBuilder("RepeatNode: { Condition: ");
sb.append(condition.toString()).append(", Statements: [");
for (StatementNode statement : statements) {
sb.append(statement.toString()).append(", ");
}
sb.delete(sb.length() - 2, sb.length());
sb.append("]}");
return sb.toString();
}
}
WhileNode.java
import java.util.ArrayList;
public class WhileNode<BooleanCompare> extends Node {
private BooleanCompare condition;
private ArrayList<StatementNode> statements;
public WhileNode(BooleanCompare condition, ArrayList<StatementNode> statements) {
this.condition = condition;
this.statements = statements;
}
public BooleanCompare getCondition() {
return condition;
}
public ArrayList<StatementNode> getStatements() {
return statements;
}
@Override
public String ToString() {
StringBuilder sb = new StringBuilder("WhileNode: { Condition: ");
sb.append(condition.toString()).append(", Statements: [");
for (StatementNode statement : statements) {
sb.append(statement.toString()).append(", ");
}
sb.delete(sb.length() - 2, sb.length());
sb.append("]}");
return sb.toString();
}
}
Trending now
This is a popular solution!
Step by step
Solved in 4 steps
Where are the methods being used that I circled in the rubric? I don't see anything. I added all the needed java files for the methods to be added for each java file shown above. Which is why I circled the methods. Please fix this and show me the methods being used that I circled for the java files.