/** * Copyright (c): Uwe Schmidt, FH Wedel * * You may study, modify and distribute this source code * FOR NON-COMMERCIAL PURPOSES ONLY. * This copyright message has to remain unchanged. * * Note that this document is provided 'as is', * WITHOUT WARRANTY of any kind either expressed or implied. */ /** * eine Klasse fuer das binaere Plus * */ //-------------------- public class BinaryMinus extends BinaryExpr { //-------------------- public BinaryMinus(Expr left, Expr right) { super(left, right); } //-------------------- // eval wertet den Operanden aus public Object eval() { // beide Operanden auswerten Object value1 = left.eval(); Object value2 = right.eval(); // - fuer int if ( value1 instanceof Integer && value2 instanceof Integer ) { return new Integer( ((Integer)value1).intValue() - ((Integer)value2).intValue() ); } // - fuer double if ( value1 instanceof Double && value2 instanceof Double ) { return new Double( ((Double)value1).doubleValue() - ((Double)value2).doubleValue() ); } // nicht erlaubtes Argument throw new IllegalArgumentException("binary - : illegal operand types"); } //-------------------- public String toString() { return "(" + left.toString() + " - " + right.toString() + ")"; } } //--------------------