CSE-8B / PA6 / starter / Sum.java
Sum.java
Raw
//File: Sum.java
//Name: Trai Pham
//Date: 02/16/2020
//Course: CSE 8B
/**

*/

public class Sum extends ArithmeticExpression{

  public Sum(ArithmeticExpression var1, ArithmeticExpression var2){
    this.a = var1;
    this.b = var2;
  }

  public Value evaluate(){
    if(!(this.a instanceof ArithmeticExpression) ||
    !(this.b instanceof ArithmeticExpression)){
      return null;
    }
    if(this.a == null || this.b == null){
      return null;
    }
    Value test01 = this.a.evaluate();
    Value test02 = this.b.evaluate();
    Value sum01 = new IntegerValue(((IntegerValue)test01).intEvaluate()+
    ((IntegerValue)test02).intEvaluate());
    return sum01;

  }
}