Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Creating card game SET in Java and below I have code that determines if the random set of cards is a set or not, but

Creating card game SET in Java and below I have code that determines if the random set of cards is a set or not, but when I run my code its never a set because the number that's prints out is always 0. if there are 0 shapes its never going to be a set, the number that prints out should either be a 1, 2, or a three and cant seem to find where in my code is the reason its always 0. I dont know whether its a problem with my Triad, TestTriad, or my Board class.

// Board class

import java.util.Arrays;

import java.util.ArrayList;

public class Board { private ArrayList> board; public Board(Deck deck) { board = new ArrayList>(); for(int row_index = 0; row_index < 3; row_index++) { board.add(new ArrayList ()); for(int col_index = 0; col_index < 4; col_index++) { board.get(row_index).add(new BoardSquare(deck.getTopCard(), row_index, col_index)); } } } public void replaceCard(Card rep_card, int row, int col) { getSquareBoard(row, col).setCard(rep_card); } public BoardSquare getSquareBoard(int row, int col) { return board.get(row).get(col); } public void add3(Deck deck) { int col_index = board.get(0).size() - 1; for(int row_index = 0; row_index < 3; row_index++) { board.get(row_index).add(new BoardSquare(deck.getTopCard(), row_index, col_index)); } } public Card getCard(int row, int col) { return getSquareBoard(row, col).getCard(); } public int numRows() { return board.size(); } public int numCols() { return board.get(0).size(); } public String toString() { int num_rows = numRows(); int num_cols = numCols(); String res = ""; for(int cpos = 0; cpos < num_rows; cpos++) { { res += getCard(cpos, cpos). toString() + "\t"; } res += " "; } return res; }

//Triad Class

public class Triad { private Card[] cards; public Triad(Card c1, Card c2, Card c3) { cards = new Card[3]; cards[0] = c1; cards[1] = c2; cards[2] = c3; }

public static boolean isSet(Card card_one, Card card_two, Card card_three) { return card_one.getColor()==card_two.getColor() && card_two.getColor()==card_three.getColor() && card_one.getShading()==card_two.getShading() && card_two.getShading()==card_three.getShading() && card_one.getShape()==card_two.getShape() && card_two.getShape()==card_three.getShape() ;

}

// Testing Triad

public class TestTriad { public static void main(String[] args) { Deck d = new Deck(); d.shuffle(); Board b = new Board(d); System.out.println(" " + b.getCard(0, 0) + " "); System.out.println(b); if(Triad.isSet(b.getCard(0, 0), b.getCard(0, 1), b.getCard(0, 2))) System.out.println("set"); System.out.println("not a set"); }

}

// Example of what I get when I run the code

Solid Diamond Red 0

Solid Diamond Red 0 Striped Diamond Red 0 Striped Squiggle Green 0

not a set

Wondering if anyone can see what I've missed, thankyou

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

3. What are the current trends in computer hardware platforms?

Answered: 1 week ago