KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > poker > business > FortuneManagerImpl


1 package poker.business;
2
3 import poker.data.other.Fortune;
4 import java.util.Vector JavaDoc;
5 import poker.spec.*;
6 /**
7  *
8  * EnhyDraw!, beta 4, 5/21/99
9  *
10  * Copyright 1999, Larry Wolcot & Daryl Tempesta
11  * ALL rights reserved. Not for commercial use
12  * without written permission from both authors.
13  *
14  */

15 public class FortuneManagerImpl implements FortuneManager,java.io.Serializable JavaDoc {
16
17    private Vector JavaDoc fortuneList = new Vector JavaDoc(0);
18    private int lastFortuneNumber;
19
20    public void addFortune(String JavaDoc 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 JavaDoc getFortune() {
34       String JavaDoc 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