package org.geogebra.common.kernel.advanced; import org.geogebra.common.kernel.Kernel; import org.geogebra.common.kernel.arithmetic.Command; import org.geogebra.common.kernel.commands.CommandProcessor; import org.geogebra.common.kernel.geos.GeoElement; import org.geogebra.common.kernel.geos.GeoNumeric; import org.geogebra.common.main.MyError; /** * PresentValue[ <Rate>, <Number of Periods>, <Payment>, <Future Value * (optional)>, <Type (optional)> ] Like the Excel PV function */ public class CmdFinancialPV extends CommandProcessor { /** * Create new command processor * * @param kernel * kernel */ public CmdFinancialPV(Kernel kernel) { super(kernel); } @Override final public GeoElement[] process(Command c) throws MyError { int n = c.getArgumentNumber(); boolean[] ok = new boolean[n]; GeoElement[] arg; switch (n) { case 3: arg = resArgs(c); if ((ok[0] = arg[0].isGeoNumeric()) && (ok[1] = arg[1].isGeoNumeric()) && (ok[2] = arg[2].isGeoNumeric())) { AlgoFinancial algo = new AlgoFinancial(cons, c.getLabel(), (GeoNumeric) arg[0], (GeoNumeric) arg[1], (GeoNumeric) arg[2], null, null, null, AlgoFinancial.CalculationType.PV); GeoElement[] ret = { algo.getResult() }; return ret; } else if (!ok[0]) { throw argErr(app, c, arg[0]); } else if (!ok[1]) { throw argErr(app, c, arg[1]); } else { throw argErr(app, c, arg[3]); } case 4: arg = resArgs(c); if ((ok[0] = arg[0].isGeoNumeric()) && (ok[1] = arg[1].isGeoNumeric()) && (ok[2] = arg[2].isGeoNumeric()) && (ok[3] = arg[3].isGeoNumeric())) { AlgoFinancial algo = new AlgoFinancial(cons, c.getLabel(), (GeoNumeric) arg[0], (GeoNumeric) arg[1], (GeoNumeric) arg[2], null, (GeoNumeric) arg[3], null, AlgoFinancial.CalculationType.PV); GeoElement[] ret = { algo.getResult() }; return ret; } else if (!ok[0]) { throw argErr(app, c, arg[0]); } else if (!ok[1]) { throw argErr(app, c, arg[1]); } else if (!ok[2]) { throw argErr(app, c, arg[2]); } else { throw argErr(app, c, arg[3]); } case 5: arg = resArgs(c); if ((ok[0] = arg[0].isGeoNumeric()) && (ok[1] = arg[1].isGeoNumeric()) && (ok[2] = arg[2].isGeoNumeric()) && (ok[3] = arg[3].isGeoNumeric()) && (ok[4] = arg[4].isGeoNumeric())) { AlgoFinancial algo = new AlgoFinancial(cons, c.getLabel(), (GeoNumeric) arg[0], (GeoNumeric) arg[1], (GeoNumeric) arg[2], null, (GeoNumeric) arg[3], (GeoNumeric) arg[4], AlgoFinancial.CalculationType.PV); GeoElement[] ret = { algo.getResult() }; return ret; } else if (!ok[0]) { throw argErr(app, c, arg[0]); } else if (!ok[1]) { throw argErr(app, c, arg[1]); } else if (!ok[2]) { throw argErr(app, c, arg[2]); } else if (!ok[3]) { throw argErr(app, c, arg[3]); } else { throw argErr(app, c, arg[4]); } default: throw argNumErr(app, c, n); } } }