1 package test; 2 3 public class Calculate implements CalculetteInterface{ 4 5 public float acc_; 6 7 private boolean value_; 8 9 public Calculate(){ 10 value_ = false; 11 } 12 13 public void raz(){ 14 acc_ = 0; 15 } 16 17 public void add(int nb){ 18 acc_ = acc_ + nb; 19 } 20 21 public void div(int nb) throws DivideByZeroException{ 22 if (nb != 0) 23 acc_ = acc_ / nb; 24 else 25 throw new DivideByZeroException("Division par 0 impossible"); 26 } 27 28 public void changeValue(){ 29 if(value_==true) 30 value_ = false; 31 else 32 value_ = true; 33 } 34 35 public boolean getValue(){ 36 return value_; 37 } 38 39 public class DivideByZeroException extends Exception { 40 41 public DivideByZeroException(){ 42 super(); 43 } 44 45 public DivideByZeroException(String message){ 46 super(message); 47 } 48 49 } 50 51 } 52 53 54 55 56 | Popular Tags |