#help with constructor

6 messages · Page 1 of 1 (latest)

prime dome
#

So Im working on a assignment and im stuck on the constructor

public class BingoCard {
    
    // Instance Variables
    public int[][] card;
    public boolean[][] taken;
    
    // MY_WINNER Constant
    public static final int[] MY_WINNER = {7, 15, 4, 10, 9, 26, 16, 18, 24, 21, 32, 39, 42, 37, 58, 59, 49, 52, 50, 74, 65, 75, 71, 68};
    
    public BingoCard(int[] data) {
        // Winning drawn numbers array
        int [] winningNumbers = {73, 20, 23, 7, 32, 1, 16, 29, 68, 38, 52, 17};
        
        //Setting up a 5 by 5 array for card and taken
        this.card = new int [5][5];
        this.taken = new boolean [5][5];
        
        //Setting the center to true while keeping the remaining spaces false
        this.taken[2][2] = true;
        
        //Array of length 5 to store values that are present in MY_WINNER and data. Each index of the Array will be dedicated to column Array[0] would be for value that belong to "B" (1 to 15)
        int[] winnersInData = new int[5];
        for (int i = 0; i < data.length; i++) {
            for (int j = 0; j < winningNumbers.length; j++) {
                // If the value is in column B and it is not >=1 and <= 15 will return false
                if (data[i] == winningNumbers[j] && (data[i] >=1 && data[i] <= 15)) {
                    winnersInData[0] = data[i]; 
                }
                // If the value is in column I and it is not >=16 and <= 30 will return false
                else if (data[i] == winningNumbers[j] && (data[i] >=16 && data[i] <= 30)) {
                    winnersInData[1] = data[i]; 
                }
                // If the value is in column N and it is not >=31 and <= 45 will return false
                else if (data[i] == winningNumbers[j] && (data[i] >=31 && data[i] <= 45)) {
                    winnersInData[2] = data[i]; 
                }
                // If the value is in column G and it is not >=46 and <= 60 will return false
                else if (data[i] == winningNumbers[j] && (data[i] >=46 && data[i] <= 60)) {
                    winnersInData[3] = data[i]; 
                }
                // If the value is in column O and it is not >=61 and <= 75 will return false
                else if (data[i] == winningNumbers[j] && (data[i] >=61 && data[i] <= 75)) {
                    winnersInData[4] = data[i]; 
                }
                
            }
        }
        
        if (winnersInData[0] != 0 && winnersInData[1] != 0 && winnersInData[2] != 0 && winnersInData[3] != 0 && winnersInData[4] != 0) {
            this.card[0] = winnersInData;
            cardSetter (data, this.card);
        }
        else if (winnersInData[0] != 0 && winnersInData[1] != 0 && winnersInData[2] == 0 && winnersInData[3] != 0 && winnersInData[4] != 0) {
            cardSetter (data, this.card);
            this.card[2] = winnersInData;
        }else {
            cardSetter (data, this.card);
        }
        
        
        
    }
    
    private int [][] cardSetter(int[] data, int[][] card){
        int indexIncrement = 0;
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 5; j++) {
                if (i == 2 && j == 2) {
                    continue;
                }
                if (card[j][i] == data[indexIncrement]) {
                    indexIncrement++;
                    continue;
                }
                else if (card[j][i] == 0) {
                    card[j][i] = data[indexIncrement];
                    indexIncrement++;
                }

                
            }
        }
        return card;
    }
}

this is what I have so far

#

this is the output im getting

#

so we have a linear array that gets passed into the constructor and we need to add the numbers column by column
you have a winner if u have at least one number in B, I, G, O from the linear array thats also present in int [] winningNumbers = {73, 20, 23, 7, 32, 1, 16, 29, 68, 38, 52, 17};

you could also have a number in "N" but since the center of the card is free its not necessary

so for instance from the linear array {7, 15, 4, 10, 9, 26, 16, 18, 24, 21, 32, 39, 42, 37, 58, 59, 49, 52, 50, 74, 65, 75, 71, 68}. the winning numbers would be {7, 16, 32, 52, 68}

#

I dont want any repeats in the card like 16 or 32

earnest dome
#

"output"? "winner"?
You're supposed to make a constructor for a bingo card

#

Just have a table with numbers in