Question: IN JAVA: 1. Complete the ElevensBoard class found below, implementing the following methods. Abstract methods from the Board class: a. isLegal This method is described
IN JAVA:
1. Complete the ElevensBoard class found below, implementing the following methods.
Abstract methods from the Board class:
a. isLegal This method is described in the method heading and related comments below. The implementation should check the number of cards selected and utilize the ElevensBoard helper methods.
/**
* Determines if the selected cards form a valid group for removal.
* In Elevens, the legal groups are (1) a pair of non-face cards
* whose values add to 11, and (2) a group of three cards consisting of
* a jack, a queen, and a king in some order.
* @param selectedCards the list of the indexes of the selected cards.
* @return true if the selected cards form a valid group for removal;
* false otherwise.
*/
@Override
public boolean isLegal(List
b. anotherPlayIsPossible This method should also utilize the helper methods. It should be very short.
/**
* Determine if there are any legal plays left on the board.
* In Elevens, there is a legal play if the board contains
* (1) a pair of non-face cards whose values add to 11, or (2) a group
* of three cards consisting of a jack, a queen, and a king in some order.
* @return true if there is a legal play left on the board;
* false otherwise.
*/
@Override
public boolean anotherPlayIsPossible()
ElevensBoard helper methods:
c. containsPairSum11 This method determines if the selected elements of cards contain a pair of cards whose point values add to 11.
/**
* Check for an 11-pair in the selected cards.
* @param selectedCards selects a subset of this board. It is this list
* of indexes into this board that are searched
* to find an 11-pair.
* @return true if the board entries indexed in selectedCards
* contain an 11-pair; false otherwise.
*/
private boolean containsPairSum11(List
d. containsJQK This method determines if the selected elements of cards contains a jack, a queen, and a king in some order.
/**
* Check for a JQK in the selected cards.
* @param selectedCards selects a subset of this board. It is this list
* of indexes into this board that are searched
* to find a JQK-triplet.
* @return true if the board entries indexed in selectedCards
* include a jack, a queen, and a king; false otherwise.
*/
private boolean containsJQK(List
ElevensBoard:
import java.util.List; import java.util.ArrayList;
/** * The ElevensBoard class represents the board in a game of Elevens. */ public class ElevensBoard extends Board {
/** * The size (number of cards) on the board. */ private static final int BOARD_SIZE = 9;
/** * The ranks of the cards for this game to be sent to the deck. */ private static final String[] RANKS = {"ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "jack", "queen", "king"};
/** * The suits of the cards for this game to be sent to the deck. */ private static final String[] SUITS = {"spades", "hearts", "diamonds", "clubs"};
/** * The values of the cards for this game to be sent to the deck. */ private static final int[] POINT_VALUES = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 0, 0};
/** * Flag used to control debugging print statements. */ private static final boolean I_AM_DEBUGGING = false;
/** * Creates a new ElevensBoard instance. */ public ElevensBoard() { super(BOARD_SIZE, RANKS, SUITS, POINT_VALUES); }
/** * Determines if the selected cards form a valid group for removal. * In Elevens, the legal groups are (1) a pair of non-face cards * whose values add to 11, and (2) a group of three cards consisting of * a jack, a queen, and a king in some order. * @param selectedCards the list of the indices of the selected cards. * @return true if the selected cards form a valid group for removal; * false otherwise. */ @Override public boolean isLegal(List
/** * Determine if there are any legal plays left on the board. * In Elevens, there is a legal play if the board contains * (1) a pair of non-face cards whose values add to 11, or (2) a group * of three cards consisting of a jack, a queen, and a king in some order. * @return true if there is a legal play left on the board; * false otherwise. */ @Override public boolean anotherPlayIsPossible() { /* *** TO BE IMPLEMENTED IN ACTIVITY 9 *** */ }
/** * Check for an 11-pair in the selected cards. * @param selectedCards selects a subset of this board. It is list * of indexes into this board that are searched * to find an 11-pair. * @return true if the board entries in selectedCards * contain an 11-pair; false otherwise. */ private boolean containsPairSum11(List
/** * Check for a JQK in the selected cards. * @param selectedCards selects a subset of this board. It is list * of indexes into this board that are searched * to find a JQK group. * @return true if the board entries in selectedCards * include a jack, a queen, and a king; false otherwise. */ private boolean containsJQK(List
When you have completed these methods, run the main method found below. Make sure that the Elevens game works correctly. Note that the cards directory must be in the same directory with your .class files.
/** * This is a class that plays the GUI version of the Elevens game. * See accompanying documents for a description of how Elevens is played. */ public class ElevensGUIRunner {
/** * Plays the GUI version of Elevens. * @param args is not used. */ public static void main(String[] args) { Board board = new ElevensBoard(); CardGameGUI gui = new CardGameGUI(board); gui.displayGame(); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
