This is supposed to have a Processor, Expression, Sum, Number and Product class. Processor execute Expression and expression should execute Sum and Product maybe even number. I'm not too sure about that.
This goes to Number class Expression e1 = new Number(2.0);
public Number(double operand) {
Double code = new Double(operand);
code.toString();
System.out.println("double : " + code);
return;
This passes fine. I get the number
public class TestSOP {
public static void main(String[] args) {
Processor proc = new Processor();
Expression e1 = new Number(2.0);
Expression e2 = new Number(3.1);
Expression e3 = new Number(-5.0);
Sum s1 = new Sum(e1, e2, e3);
System.out.println("s1 - " + proc.execute(s1));
Product p1 = new Product(s1, e3);
System.out.println("s1 - " + proc.execute(s1));
// etc.
}
}
The problem is this line Sum s1 = new Sum(e1, e2, e3); the Sum has a constructor that has to pass the expression. I have tried many different ways after passing the operand to get it into a double but all I get is SOP.Number@566776ad. I'm not sure what to do or try next Bellow is the Sum Class.
public class Sum implements Expression {
public Sum(Expression ...operand ) {
SOP.Number.Numbers(operand); }