Question
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.
import java.util.Arrays;
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) { boolean number = false; boolean color = false; boolean shape = false; boolean shading = false; if(card_one.number == card_two. number && card_one.number == card_three.number) number = true; else if(card_one.number != card_two. number && card_two.number != card_three.number && card_one. number != card_three.number) number = true; if(card_one.shading == card_two.shading && card_one.shading == card_three. shading) shading = true; else if(card_one.shading != card_two. shading && card_two.shading != card_three.shading && card_one.shading != card_three.shading) shading = true; if(card_one.shape == card_two. shape && card_one.shape == card_three.shape) shape = true; else if(card_one.shape != card_two. shape && card_two.shape != card_three.shape && card_one.shape != card_three.shape) shape = true; if(card_one.color == card_two. color && card_one.color == card_three.color) color = true; else if(card_one.color != card_two. color && card_two.color != card_three.color && card_one.color != card_three.color) color = true; boolean isSet = number && color && shading && shape; return isSet; } @Override public String toString() { return String.format("First Card: %s " + " Second Card: %s " + " Third Card: %s ", cards[0].toString(), cards [1].toString(), cards[2].toString()); }
// 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started