1 package poker.business; 2 3 import poker.data.other.Fortune; 4 import java.util.Vector ; 5 import poker.spec.*; 6 15 public class FortuneManagerImpl implements FortuneManager,java.io.Serializable { 16 17 private Vector fortuneList = new Vector (0); 18 private int lastFortuneNumber; 19 20 public void addFortune(String fortune) { 21 22 int num = 1; 23 if (fortuneList.size() > 1) { 24 Fortune lastFortune = (Fortune)fortuneList.lastElement(); 25 num = lastFortune.getFortuneNumber() + 1; 26 } 27 28 Fortune newFortune = new Fortune(num, fortune); 29 newFortune.setHasBeenUsed(false); 30 fortuneList.addElement(newFortune); 31 } 32 33 public String getFortune() { 34 String fortune = ""; 35 if (fortuneList.size() == 0) { 36 fortune = ""; 37 } 38 else { 39 Fortune nextFortune = (Fortune)fortuneList.elementAt(lastFortuneNumber); 40 fortune = nextFortune.getFortune(); 41 lastFortuneNumber++; 42 } 43 44 if (lastFortuneNumber >= fortuneList.size()){ 45 lastFortuneNumber = 0; 46 } 47 48 return fortune; 49 } 50 51 } 52 | Popular Tags |