Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Java I have a card game called SET and I need some help creating a couple classes I'm calling Group and Simulation, the Group

In Java I have a card game called SET and I need some help creating a couple classes I'm calling Group and Simulation, the Group class needs to extend my Deck class and have an Iterable interface. The Group class basically is supposed to show if I had a SET how many sets I had. The main method should be in the Simulation class. It should allow the user to input a number of cards to deal (e.g. students in the class), 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. below are my Card(attributes of the cards), Triad(determines whether the cards are a SET or not) and my Deck classes. Any help I can get with this will be appreciated, thankyou.

import com..set.Card.Color; import com..set.Card.Shading; import com..set.Card.Shape; import com..set.Card.Number;

public class Card { //public enum declarations public enum Shape{Oval, Squiggle, Diamond}; public enum Shading{Solid, Striped, Outlined}; public enum Number{One, Two, Three}; public enum Color{Red, Green, Purple}

// class number variable declaration Shading shading; Shape shape; Color color; Number number; //Constructor public Card(Shape shape, Color colors, Shading shading, Number number) { this.shape = shape; this.color = colors; this.shading = shading; this.number = number; }

public Shading getShading() { return shading; } public Shape getShape() { return shape; } public Color getColor() { return color; } public Number getNumber() { return number; } @Override public String toString() { String cardString = ""; cardString += shape +" "; cardString += color +" "; cardString += shading +" "; cardString += number; return cardString; } }

*******************************************************************************************************

import java.util.Arrays;

import com.DustinNichols.set.Card;

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.length; i ++) { triadCards[i] = String.format("%-20s",triadCards[i]); } } else { String [] cardStrings = card.toString().split(" "); for (int i = 0; i < cardStrings.length; 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());

} }

********************************************************************

import java.util.ArrayList; import java.util.Collections;

public class Deck extends Group { public final static int CARDS_IN_DECK = 81; public ArrayList deck; //Constructor that represents a fresh deck public Deck(ArrayList cards) { for (Card.Shading shading: Card.Shading.values()) { for (Card.Shape shape: Card.Shape.values()) { for (Card.Color color: Card.Color.values()) { for (Card.Number number: Card.Number.values()) { cards.add(new Card(shape, color, shading, number)); } } } } }

//method shuffle randomizes the order of the cards public void shuffleDeck() { Collections.shuffle(deck); } //method isEmpty determines if the deck has cards in it public boolean isEmpty() { return (deck.size() == 0); }

//method getTopCard //deals a card, returns it, and removes it from the deck //@return c public Card getTopCard() { Card c = deck.remove(deck.size()-1); return c; }

// method toString // turns the deck into a string and returns it // @return str public String toString() { String str="Current Deck: "; for (int i=0; i < deck.size() ; i++) { str+= deck.get(i).toString(); } return str; }

public ArrayList getCards() { return deck; } }

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

Students also viewed these Databases questions

Question

2. What is the impact of information systems on organizations?

Answered: 1 week ago

Question

Evaluate the impact of technology on HR employee services.

Answered: 1 week ago