/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package servlets; /** * * @author javamobile */ public class Arvutaja { int a1, a2; public Arvutaja(int arv1, int arv2){ a1=arv1; a2=arv2; } public Arvutaja(String arv1, String arv2){ this(Integer.parseInt(arv1), Integer.parseInt(arv2)); } public int korrutis(){ return a1*a2; } public int summa(){ return a1+a2; } public int vahe(){ return a1-a2; } public int suhe(){ return a1/a2; } public int tehe(String symbol){ if(symbol.equals("*")){return korrutis();} if(symbol.equals("/")){return suhe();} if(symbol.equals("+")){return summa();} if(symbol.equals("-")){return vahe();} throw new RuntimeException("Tundmatu tehe"); } }