Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The Game of SET - Part I Due Monday, October 30th. Complete javadocs documentati

ID: 3604785 • Letter: T

Question

The Game of SET - Part I Due Monday, October 30th. Complete javadocs documentation is required 15points/class - 60 points total SET is a card game that can be played solo or with several people. There are 81 cards in the deck. Each card has 4 features: a shape (oval, squiggle or diamond), a color (red, purple, green), a number (one, two or three) and a fil (solid, striped, outlined) Color ovals, squiggles purp le or diamonds or green Number Shading solid, 001 striped, or three or outlined Set A "set" consists of 3 cards in which each of the cards' features are the same on each card or different on each card. examples and more information about the game can be found at setgame.com. The game begins by placing 12 cards face up (a 4x3 grid of cards). The player identifies sets of cards. When a set is identified, the three cards are removed from the board and replaced with three new cards from the deck. If, at any time the player decides there are no sets in the 12 cards, they may flip 3 more cards. If there are still no sets, they may flip 3 more cards. The maximum number of cards, face up on the table, at any time is 18. The play continues until the deck is depleted Implementation Phase I We will be implementing this game in three phases. Each phase is dependent up on the prior phase, so it is imperative that you do not fall behind. We will be implementing a solitaire version. For the first phase, due Monday, October 30th, you will implement the following classes: Card class represent one card. Each card has 4 features. Use enumerated types to represent the possible values for each features (for example: OUTLINE, SOLID, HATCHED). The class has only one constructor that accepts a Color, Fill Rank and Number. Once a Card is created; it is never changed. Implement at toString) method. Include a class (static) method that takes 3 Cards and determines if they form a set. Deck class-an ArrayList of Card Objects. The class has only one constructor, a default (no-arg) constructor that creates the 81 card deck. Include methods for shuffle ), toString, isEmpty and getTopCard. The getTopCard method should return a reference to the Card being removed from the Deck (not a copy!). BoardSquare class Each square on the "board" will contain a Card, as well its row, col position in the Board and some indication of whether or not the square is selected. The class has a single constructor that takes in a card, an integer row position, an integer column position. The BoardSquare is initialized to be unselected. Implement getters and setters for all instance variables.

Explanation / Answer


Given below is the code for the question.
To indent code in eclipse, select code and press Ctrl+a and then Ctrl+i.
Please don't forget to rate the answer if it helped. Post a comment in case of any issues.



public class Card {
public enum Color {RED, PURPLE, GREEN};
public enum Shape {OVAL, SQUARE, DIAMOND};
public enum Fill {SOLID, HATCHED, OUTLINE};
private int rank;
private Color color;
private Shape shape;
private Fill fill;
public Card(int rank, Color c, Shape s, Fill f)
{
this.rank = rank;
this.color =c;
this.shape = s;
this.fill =f;
}
public String toString()
{
return rank + "_" + color + "_" + shape + "_" + fill;
}
public static boolean isSet(Card c1, Card c2, Card c3)
{
boolean rankOk = false;
boolean colorOk = false;
boolean shapeOk = false;
boolean fillOk = false;
//check rank
if(c1.rank == c2.rank && c1.rank == c3.rank) //all ranks same
rankOk = true;
else if(c1.rank != c2.rank && c2.rank != c3.rank && c1.rank != c3.rank) //all ranks different
rankOk = true;
//check fill
if(c1.fill == c2.fill && c1.fill == c3.fill) //all fill same
fillOk = true;
else if(c1.fill != c2.fill && c2.fill != c3.fill && c1.fill != c3.fill) //all fill different
fillOk = true;
//check shape
if(c1.shape == c2.shape && c1.shape == c3.shape) //all shape same
shapeOk = true;
else if(c1.shape != c2.shape && c2.shape != c3.shape && c1.shape != c3.shape) //all shape different
shapeOk = true;
//check color
if(c1.color == c2.color && c1.color == c3.color) //all color same
colorOk = true;
else if(c1.color != c2.color && c2.color != c3.color && c1.color != c3.color) //all color different
colorOk = true;
boolean set = rankOk && colorOk && fillOk && shapeOk;
return set;
}
}

=========================
import java.util.ArrayList;
public class Deck {
private ArrayList<Card> cards;
public Deck()
{
Card.Color[] colors = Card.Color.values();
Card.Fill[] fills = Card.Fill.values();
Card.Shape[] shapes = Card.Shape.values();
cards = new ArrayList<Card>();
//create the 81 cards,
for(int rank = 1; rank <= 3; rank++)
{
for(int c = 0; c < colors.length; c++)
for(int s = 0; s < shapes.length; s++)
for(int f = 0; f < fills.length; f++)
cards.add(new Card(rank, colors[c], shapes[s], fills[f]));
}
}
public void shuffle()
{
for(int i = 0; i < cards.size(); i++)
{
//swap with some random card
int rndIdx =(int) (Math.random() * cards.size());
Card temp = cards.get(i);
cards.set(i, cards.get(rndIdx));
cards.set(rndIdx, temp);
}
}
public boolean isEmpty()
{
return cards.size() == 0;
}
public Card getTopCard()
{
if(!isEmpty())
return cards.remove(0);
else
return null;
}
public String toString()
{
String str = "";
for(Card c: cards)
str += c + " ";
return str;
}
}






=========================



public class BoardSquare {
private Card card;
private int row, col;
boolean selected;
public BoardSquare(Card card, int r, int c)
{
this.card = card;
this.row = r;
this.col = c;
this.selected = false;
}
public Card getCard() {
return card;
}
public void setCard(Card card) {
this.card = card;
}
public int getRow() {
return row;
}
public void setRow(int row) {
this.row = row;
}
public int getCol() {
return col;
}
public void setCol(int col) {
this.col = col;
}
public boolean isSelected() {
return selected;
}
public void setSelected(boolean selected) {
this.selected = selected;
}
}



===============



import java.util.ArrayList;
public class Board {
private ArrayList<ArrayList<BoardSquare>> board;
public Board(Deck deck)
{
board = new ArrayList<ArrayList<BoardSquare>>();
for(int row = 0; row < 3; row++)
{
board.add(new ArrayList<BoardSquare> ());
for(int col = 0; col < 4; col++)
{
board.get(row).add(new BoardSquare(deck.getTopCard(), row, col));
}
}
}
public void replaceCard(Card newCard, int row, int col)
{
getBoardSquare(row, col).setCard(newCard);
}
public BoardSquare getBoardSquare(int row, int col)
{
return board.get(row).get(col);
}
public void add3(Deck deck)
{
int col = board.get(0).size() - 1;
for(int row = 0; row < 3; row++)
{
board.get(row).add(new BoardSquare(deck.getTopCard(), row, col));
}
}
public Card getCard(int row, int col)
{
return getBoardSquare(row, col).getCard();
}
public int numRows()
{
return board.size();
}
public int numCols()
{
return board.get(0).size();
}
public String toString()
{
int rows = numRows();
int cols = numCols();
String str = "";
for(int r = 0; r < rows; r++)
{
for(int c = 0; c < cols; c++)
{
str += getCard(r, c).toString() + " ";
}
str += " ";
}
return str;
}
}







==========







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









========



OUTPUT
3_PURPLE_SQUARE_HATCHED 1_RED_SQUARE_SOLID 2_GREEN_SQUARE_SOLID 1_GREEN_OVAL_OUTLINE
1_PURPLE_SQUARE_HATCHED 2_GREEN_OVAL_SOLID 3_GREEN_DIAMOND_HATCHED 2_GREEN_DIAMOND_HATCHED
3_PURPLE_DIAMOND_SOLID 1_RED_OVAL_OUTLINE 2_PURPLE_DIAMOND_HATCHED 2_RED_OVAL_OUTLINE

3_PURPLE_SQUARE_HATCHED
3_PURPLE_SQUARE_HATCHED 1_RED_SQUARE_SOLID 2_GREEN_SQUARE_SOLID 1_GREEN_OVAL_OUTLINE
1_PURPLE_SQUARE_HATCHED 2_GREEN_OVAL_SOLID 3_GREEN_DIAMOND_HATCHED 2_GREEN_DIAMOND_HATCHED
3_PURPLE_DIAMOND_SOLID 1_RED_OVAL_OUTLINE 2_PURPLE_DIAMOND_HATCHED 2_RED_OVAL_OUTLINE
not a set

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote