1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import java.util.HashMap;
import java.util.Random;
import java.util.Set;

// needed for user input
import java.util.Scanner;

class Bingo {

    private HashMap<Integer,String> pool = new HashMap<Integer,String>();
    private HashMap<Integer,String> history = new HashMap<Integer,String>();
    private String ball;

    public Bingo() {
        for ( int i = 1; i < 76; i++ ){
            if ( i <= 15 ){
                this.pool.put( i, "B" );
            }
            if ( i > 15 && i <= 30 ){
                this.pool.put( i, "I" );
            }
            if ( i > 30 && i <= 45 ){
                this.pool.put( i, "N" );
            }
            if ( i > 45 && i <= 60 ){
                this.pool.put( i, "G" );
            }
            if ( i > 60 && i <= 75 ){
                this.pool.put( i, "0" );
            }
        }
    }

    public String draw() {
        /***Draw a ball, remove from pool, put in history, return ball***/
        Choice c = new Choice( this.pool.keySet() );
        Integer pick = (Integer)c.get(); // work with objects, cast to int

        this.ball = String.format( "%s%d", pool.get(pick), pick );
        this.history.put( pick, pool.get(pick) );
        this.pool.remove( pick );
        return ball;
    }

    public String ball(){
        return this.ball;
    }
    public HashMap pool(){
        return this.pool;
    }
    public HashMap history(){
        return this.history;
    }
}

class TestBingo {
    public static void main( String args[] ) throws Exception {
        Scanner raw_input = new Scanner( System.in );
        Bingo bingo = new Bingo();
        String response;

        Boolean nowinner = true;
        while ( nowinner ){
            String ball = bingo.draw();
            System.out.println( ball );
            System.out.print( "Was there a winner? [y,n]: " );
            response = raw_input.next();
            if ( response.equals( "y" ) ){
                System.out.println( "Play again soon!" );
                nowinner = false;
            }
        }
    }
}


class Choice {
    public Set S;

    public Choice( Set S ){
        this.S = S;
    }

    public Object get(){
        Random rand = new Random();
        Object A[];
        A = this.S.toArray( );
        return A[ rand.nextInt( A.length ) ];
    }
}