Question
My code compiles fine in eclipse, but it wont compile in the program my teacher is grading in. He is using putty(a terminal emulator) to
My code compiles fine in eclipse, but it wont compile in the program my teacher is grading in. He is using putty(a terminal emulator) to run the program. Here are his instructions :
What do I need to change in my source code to make it work in these conditions? Below is my source code. Please provide the compileable code, how you save the files, and screenshots of it compiling in a terminal emulator.
Here is my source code:
ExpressionTree.java
//
import java.util.HashMap; import java.util.Iterator; import java.util.Stack;
public class ExpressionTree extends BinaryTree
ExpressionTreeInterface.java
public interface ExpressionTreeInterface
Variable.java
public class Variable { private String name; private double value; public Variable(String name) { this.name = name; } public Variable(String name, double value) { this.name = name; this.setValue(value); } public String getName() { return name; } public void setName(String newName) { this.name = newName; }
public double getValue() { return value; }
public void setValue(double value) { this.value = value; } }
BinaryNode.java
public class BinaryNode
public BinaryNode
public void setRightChild(BinaryNode
BinaryTree.java
import java.util.Iterator; import java.util.Stack;
public class BinaryTree
private BinaryNode
public BinaryTree() { root = null; }
public BinaryTree(T rootData) { root = new BinaryNode
public BinaryTree(T rootData, BinaryTree
public void setTree(T rootData) { root = new BinaryNode
public void setTree(T rootData, BinaryTree
private void privateSetTree(T rootData, BinaryTree
if ((left != null) && (!left.isEmpty())) { root.setLeftChild(left.root.copy()); } if ((right != null) && (!right.isEmpty())) { root.setRightChild(right.root.copy()); } }
public T getRootData() { return root.getData(); }
public int getHeight() { return root.getHeight(); }
public int getNumberOfNodes() { return root.getNumberOfNodes(); }
public boolean isEmpty() { return root == null; }
public void clear() { root = null; }
protected BinaryNode
public Iterator
public Iterator
public Iterator
public Iterator
private class PostorderIterator implements Iterator
private Stack
public PostorderIterator() { nodeStack = new Stack(); current = root; populateStack(current); } private void populateStack(BinaryNode
public boolean hasNext() { return !nodeStack.isEmpty(); }
public T next() { return nodeStack.pop().getData(); }
}
}
BinaryTreeInterface.java
public interface BinaryTreeInterface
TreeIteratorInterface.java
import java.util.Iterator;
public interface TreeIteratorInterface
TreeInterface.java
public interface TreeInterface
ExpressionTest.java
package TreePackage;
import java.util.InputMismatchException;
import java.util.Scanner;
public class ExpressionTest {
public static boolean isDouble(String value) {
try {
Double.parseDouble(value);
return true;
} catch (NumberFormatException e) {
return false;
}
}
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
boolean hasExpression = false;
boolean quit = false;
String userInput = null;
ExpressionTree exp = new ExpressionTree(new String[]{"a", "b", "2", "/","+"});
while(!quit){
System.out.print(" J. Botkin's Expression Tree ");
if(hasExpression){
System.out.println("Current Expression: " + userInput
+ "");
}
System.out.println(" 1. Enter New Expression "
+ "2. Set Expression Variable "
+ "3. Evaluate Expression "
+ "4. Display Postfix "
+ "5. Quit");
try{
int option = kb.nextInt();
switch (option) {
case 1:
System.out.println("Enter Expression seperated by spaces.");
Scanner b = new Scanner(System.in);
userInput = b.nextLine();
String[] userExp = userInput.split(" ");
switch (userExp.length){
case 1:
exp = new ExpressionTree(new String[]{userExp[0]});
break;
case 2:
exp = new ExpressionTree(new String[]{userExp[0], userExp[1]});
break;
case 3:
exp = new ExpressionTree(new String[]{userExp[0], userExp[1], userExp[2]});
break;
case 4:
exp = new ExpressionTree(new String[]{userExp[0], userExp[1], userExp[2], userExp[3]});
break;
case 5:
exp = new ExpressionTree(new String[]{userExp[0], userExp[1], userExp[2], userExp[3],userExp[4]});
break;
case 6:
exp = new ExpressionTree(new String[]{userExp[0], userExp[1], userExp[2], userExp[3],userExp[4], userExp[5]});
break;
case 7:
exp = new ExpressionTree(new String[]{userExp[0], userExp[1], userExp[2], userExp[3],userExp[4], userExp[5],userExp[6]});
break;
case 8:
exp = new ExpressionTree(new String[]{userExp[0], userExp[1], userExp[2], userExp[3],userExp[4], userExp[5],userExp[6], userExp[7]});
break;
case 9:
exp = new ExpressionTree(new String[]{userExp[0], userExp[1], userExp[2], userExp[3],userExp[4], userExp[5],userExp[6], userExp[7], userExp[8]});
break;
}
/*for(int i = 0; i
if(isDouble(userExp[i])){
exp.setVariable(userExp[i], Double.parseDouble(userExp[i]));
}
}
hasExpression = true;*/
break;
case 2:
Scanner k = new Scanner(System.in);
System.out.print("Variable name: ");
String name = k.nextLine();
System.out.print("Variable value: ");
double value = k.nextDouble();
exp.setVariable(name, value);
break;
case 3:
try{
System.out.println(exp.evaluate());
}
catch (IllegalArgumentException e){
System.out.println("Please define all variables.");
}
break;
case 4:
try{
exp.displayPostfix();
}catch(IllegalArgumentException e){
System.out.println("Please define all variables.");
}
break;
case 5:
quit = true;
break;
default:
System.out.println("Enter Correct option.");
break;
}}catch(InputMismatchException e){
System.out.println("Enter Correct option.");
main(args);
}
}
}
}
2. Compress all the source codes (*.java) into a single zip file with the structure: proj1.zip ExpressionTest.java TreePackage/ BinaryNode. java and submit it with the following name: flast-projl zip, where flast is your first initial and last name, lowercase. cp proj1.zip /user/ You should check out your project on theintranet using cp projl.zip /users24102/flast-proj1.zip /cs24102/flast-projl.zip javac ExpressionTest.java java ExpressionTestStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started