/** * 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 zum Konvertieren von int Operanden * in double Operanden * */ //-------------------- public class IntToDouble extends UnaryExpr { //-------------------- public IntToDouble(Expr operand) { super(operand); } //-------------------- // eval wertet den Operanden aus // und konvertiert ihn nach double public Object eval() { // operand auswerten Object value = operand.eval(); // int to double Konversion if ( value instanceof Integer ) { return new Double( ((Integer)value).doubleValue() ); } // nicht erlaubtes Argument throw new IllegalArgumentException("int to double: illegal operand type"); } //-------------------- public String toString() { return "((double)" + operand.toString() + ")"; } } //--------------------