1 15 package org.apache.hivemind.management; 16 17 import java.util.Random ; 18 19 20 24 public class CalculatorImpl implements Calculator 25 { 26 private int _sum = 0; 27 private Random random = new Random (System.currentTimeMillis()); 28 29 public int getSum() 30 { 31 return _sum; 32 } 33 34 public void add(int value) 35 { 36 sleepRandom(); 37 _sum += value; 38 } 39 40 public void subtract(int value) 41 { 42 sleepRandom(); 43 _sum -= value; 44 } 45 46 public void multiply(int value) 47 { 48 sleepRandom(); 49 _sum *= value; 50 } 51 52 public void clear() 53 { 54 sleepRandom(); 55 _sum = 0; 56 } 57 58 62 public void sleepRandom() 63 { 64 try 65 { 66 Thread.sleep(random.nextInt(100)); 67 } 68 catch (InterruptedException e) 69 { 70 } 71 } 72 } 73 | Popular Tags |