Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Creating a version of the card game SET in Java, using classes Card, Triad, Group, Deck, and Simulation. I have the Card and Triad classes

Creating a version of the card game SET in Java, using classes Card, Triad, Group, Deck, and Simulation. I have the Card and Triad classes created already(below) but I need the other 3. Just need a simple Deck class to shuffle and deal 12 random cards out in groups of 4 based on the attributes of the cards - number, shading, color, and shape and each attribute assumes one of three possible values, Number: { One, Two, Three } Shading: { Solid, Striped, Outlined } Color: { Red, Green, Purple } Shape: { Ovals, Squiggles, Diamonds }. Example: Oval Striped Green 2, Squiggles Solid Purple 3, Diamonds Outlined Red 1, Squiggles Striped Red 2. The Deck class should extend Group, the Group class should implement Iterable interface and is created to show how many sets were created, so you have Triad class that should tell the user if the dealt cards either is or is not a SET and you have the Group class that returns below that says number of SETS made. The Simulation class is the main method and is the only class with a static method. This class should allow the user to input a number of cards to deal, and after dealing out that number of cards 10,000 times print how many times there was at least one set and what was the average number of sets dealt. Mainly having trouble with the Group and Simulation classes any help would be appreciated.

image text in transcribed*******************************************************

public class Triad

{

private Card[] cards = new Card[3];

public Triad(Card cardOne, Card cardTwo, Card cardThree)

{

cards[0] = cardOne;

cards[1] = cardTwo;

cards[2] = cardThree;

}

private boolean allSameOrDifferent(Enum> a, Enum> b, Enum> c)

{

if (a == b && b == c)

return true;

else if (a != b && a != c && b != c)

return true;

else

return false;

}

public boolean isSet()

{

if (allSameOrDifferent(cards[0].getShape(),cards[1].getShape(),cards[2].getShape()) &&

allSameOrDifferent(cards[0].getColor(),cards[1].getColor(),cards[2].getColor()) &&

allSameOrDifferent(cards[0].getShading(),cards[1].getShading(),cards[2].getShading()) &&

allSameOrDifferent(cards[0].getNumber(),cards[1].getNumber(),cards[2].getNumber()))

return true;

else

return false;

}

@Override

public String toString()

{

String triadString = "";

String[] triadCards = new String[0];

for (Card card: cards)

{

if (triadCards.length == 0){

triadCards = card.toString().split(" ");

for (int i = 0; i

{

triadCards[i] = String.format("%-20s",triadCards[i]);

}

}

else

{

String [] cardStrings = card.toString().split(" ");

for (int i = 0; i

triadCards[i] += " | " + String.format("%-20s",cardStrings[i]);

}

}

}

triadString += String.join(" ",triadCards);

return triadString;

}

public static void main(String[] args)

{

Card testCard = new Card(Card.Shape.SQUIGGLE,Card.Color.PURPLE,Card.Shading.STRIPED,Card.Number.THREE);

Card testCard2 = new Card(Card.Shape.DIAMOND,Card.Color.PURPLE,Card.Shading.STRIPED,Card.Number.THREE);

Card testCard3 = new Card(Card.Shape.DIAMOND,Card.Color.PURPLE,Card.Shading.STRIPED,Card.Number.THREE);

Triad testTriad = new Triad(testCard, testCard2, testCard3);

System.out.println(testTriad);

System.out.println(testTriad.isSet());

}

}

public class Card //public enum declarations public enum Shape(Oval, Squiggle, Diamond public enum ShadinglSolid, Striped, Outlined), public enum Number(One, Two, Three); public enum Color Red, Green , Purple) l/ class number variable declaration Shading shading: Shape shape Color color int number public Card(int Number, Color colors, Shape shapes, Shading shading) this.number number this.color colors this, shapeshapes; this.shading shading public Shading getshading() return shading public Shape getShapel) return shape; public Color getColor return color public int getNumber return number public String toStringl String cardString" cardStringshading+n cardString shape +" ", cardString+ color"n cardString+number return cardString public class Card //public enum declarations public enum Shape(Oval, Squiggle, Diamond public enum ShadinglSolid, Striped, Outlined), public enum Number(One, Two, Three); public enum Color Red, Green , Purple) l/ class number variable declaration Shading shading: Shape shape Color color int number public Card(int Number, Color colors, Shape shapes, Shading shading) this.number number this.color colors this, shapeshapes; this.shading shading public Shading getshading() return shading public Shape getShapel) return shape; public Color getColor return color public int getNumber return number public String toStringl String cardString" cardStringshading+n cardString shape +" ", cardString+ color"n cardString+number return cardString

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

Students also viewed these Databases questions