SlideShare ist ein Scribd-Unternehmen logo
1 von 8
Downloaden Sie, um offline zu lesen
Exercises (write all 4 methods!):
1. Complete the ElevensBoard class in the A09 Starter Code folder, 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 selectedCards)
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 selectedCards)
d. containsJQK This method determines if the selected elements of cards contain 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 selectedCards)
import java.util.List;
import java.util.ArrayList;
/**
* The ElevensBoard class represents the board in a game of Elevens.
*/
public class ElevensBoard {
/**
* 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};
/**
* The cards on this board.
*/
private Card[] cards;
/**
* The deck of cards being used to play the current game.
*/
private Deck deck;
/**
* Flag used to control debugging print statements.
*/
private static final boolean I_AM_DEBUGGING = false;
/**
* Creates a new ElevensBoard instance.
*/
public ElevensBoard() {
cards = new Card[BOARD_SIZE];
deck = new Deck(RANKS, SUITS, POINT_VALUES);
if (I_AM_DEBUGGING) {
System.out.println(deck);
System.out.println("----------");
}
dealMyCards();
}
/**
* Start a new game by shuffling the deck and
* dealing some cards to this board.
*/
public void newGame() {
deck.shuffle();
dealMyCards();
}
/**
* Accesses the size of the board.
* Note that this is not the number of cards it contains,
* which will be smaller near the end of a winning game.
* @return the size of the board
*/
public int size() {
return cards.length;
}
/**
* Determines if the board is empty (has no cards).
* @return true if this board is empty; false otherwise.
*/
public boolean isEmpty() {
for (int k = 0; k < cards.length; k++) {
if (cards[k] != null) {
return false;
}
}
return true;
}
/**
* Deal a card to the kth position in this board.
* If the deck is empty, the kth card is set to null.
* @param k the index of the card to be dealt.
*/
public void deal(int k) {
cards[k] = deck.deal();
}
/**
* Accesses the deck's size.
* @return the number of undealt cards left in the deck.
*/
public int deckSize() {
return deck.size();
}
/**
* Accesses a card on the board.
* @return the card at position k on the board.
* @param k is the board position of the card to return.
*/
public Card cardAt(int k) {
return cards[k];
}
/**
* Replaces selected cards on the board by dealing new cards.
* @param selectedCards is a list of the indices of the
* cards to be replaced.
*/
public void replaceSelectedCards(List selectedCards) {
for (Integer k : selectedCards) {
deal(k.intValue());
}
}
/**
* Gets the indexes of the actual (non-null) cards on the board.
*
* @return a List that contains the locations (indexes)
* of the non-null entries on the board.
*/
public List cardIndexes() {
List selected = new ArrayList();
for (int k = 0; k < cards.length; k++) {
if (cards[k] != null) {
selected.add(new Integer(k));
}
}
return selected;
}
/**
* Generates and returns a string representation of this board.
* @return the string version of this board.
*/
public String toString() {
String s = "";
for (int k = 0; k < cards.length; k++) {
s = s + k + ": " + cards[k] + "n";
}
return s;
}
/**
* Determine whether or not the game has been won,
* i.e. neither the board nor the deck has any more cards.
* @return true when the current game has been won;
* false otherwise.
*/
public boolean gameIsWon() {
if (deck.isEmpty()) {
for (Card c : cards) {
if (c != null) {
return false;
}
}
return true;
}
return false;
}
/**
* 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.
*/
public boolean isLegal(List selectedCards) {
/* *** TO BE IMPLEMENTED IN ACTIVITY 9 *** */
}
/**
* 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.
*/
public boolean anotherPlayIsPossible() {
/* *** TO BE IMPLEMENTED IN ACTIVITY 9 *** */
}
/**
* Deal cards to this board to start the game.
*/
private void dealMyCards() {
for (int k = 0; k < cards.length; k++) {
cards[k] = deck.deal();
}
}
/**
* 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 selectedCards) {
/* *** TO BE IMPLEMENTED IN ACTIVITY 9 *** */
}
/**
* 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 selectedCards) {
/* *** TO BE IMPLEMENTED IN ACTIVITY 9 *** */
}
}

Weitere ähnliche Inhalte

Mehr von alphaagenciesindia

Requirements Use JavaDo Not Use RecursionDo Not Use Array Lis.pdf
Requirements Use JavaDo Not Use RecursionDo Not Use Array Lis.pdfRequirements Use JavaDo Not Use RecursionDo Not Use Array Lis.pdf
Requirements Use JavaDo Not Use RecursionDo Not Use Array Lis.pdf
alphaagenciesindia
 
Required The City of Mississauga Goes Digital The City of Mississ.pdf
Required The City of Mississauga Goes Digital The City of Mississ.pdfRequired The City of Mississauga Goes Digital The City of Mississ.pdf
Required The City of Mississauga Goes Digital The City of Mississ.pdf
alphaagenciesindia
 
Reflexiona sobre un cambio profesional importante que hayas experime.pdf
Reflexiona sobre un cambio profesional importante que hayas experime.pdfReflexiona sobre un cambio profesional importante que hayas experime.pdf
Reflexiona sobre un cambio profesional importante que hayas experime.pdf
alphaagenciesindia
 
Required Designate where each of the following events would be pre.pdf
Required  Designate where each of the following events would be pre.pdfRequired  Designate where each of the following events would be pre.pdf
Required Designate where each of the following events would be pre.pdf
alphaagenciesindia
 
Romance en la oficina buscando respuestas a tientasDescripci�n de.pdf
Romance en la oficina buscando respuestas a tientasDescripci�n de.pdfRomance en la oficina buscando respuestas a tientasDescripci�n de.pdf
Romance en la oficina buscando respuestas a tientasDescripci�n de.pdf
alphaagenciesindia
 
ROBOTICS Currently, roboticists and AI researchers are still strug.pdf
ROBOTICS Currently, roboticists and AI researchers are still strug.pdfROBOTICS Currently, roboticists and AI researchers are still strug.pdf
ROBOTICS Currently, roboticists and AI researchers are still strug.pdf
alphaagenciesindia
 
RKO-Stanley v. GrazianoEagen, J.On April 30, 1970, RKO-Stanley W.pdf
RKO-Stanley v. GrazianoEagen, J.On April 30, 1970, RKO-Stanley W.pdfRKO-Stanley v. GrazianoEagen, J.On April 30, 1970, RKO-Stanley W.pdf
RKO-Stanley v. GrazianoEagen, J.On April 30, 1970, RKO-Stanley W.pdf
alphaagenciesindia
 

Mehr von alphaagenciesindia (20)

Researchers studying the STAR data report anecdotal evidence that sc.pdf
Researchers studying the STAR data report anecdotal evidence that sc.pdfResearchers studying the STAR data report anecdotal evidence that sc.pdf
Researchers studying the STAR data report anecdotal evidence that sc.pdf
 
Research results suggest a relationship between the TV viewing habit.pdf
Research results suggest a relationship between the TV viewing habit.pdfResearch results suggest a relationship between the TV viewing habit.pdf
Research results suggest a relationship between the TV viewing habit.pdf
 
Research done by doctors show that individuals with Kreuzfeld-Jacob .pdf
Research done by doctors show that individuals with Kreuzfeld-Jacob .pdfResearch done by doctors show that individuals with Kreuzfeld-Jacob .pdf
Research done by doctors show that individuals with Kreuzfeld-Jacob .pdf
 
Requirements Use JavaDo Not Use RecursionDo Not Use Array Lis.pdf
Requirements Use JavaDo Not Use RecursionDo Not Use Array Lis.pdfRequirements Use JavaDo Not Use RecursionDo Not Use Array Lis.pdf
Requirements Use JavaDo Not Use RecursionDo Not Use Array Lis.pdf
 
Research and describe TWO diseases - The cardiovascular disease .pdf
Research and describe TWO diseases - The cardiovascular disease .pdfResearch and describe TWO diseases - The cardiovascular disease .pdf
Research and describe TWO diseases - The cardiovascular disease .pdf
 
Required The City of Mississauga Goes Digital The City of Mississ.pdf
Required The City of Mississauga Goes Digital The City of Mississ.pdfRequired The City of Mississauga Goes Digital The City of Mississ.pdf
Required The City of Mississauga Goes Digital The City of Mississ.pdf
 
Required1-a. Determine Mahomess pension expense for 2024.1-b, .pdf
Required1-a. Determine Mahomess pension expense for 2024.1-b, .pdfRequired1-a. Determine Mahomess pension expense for 2024.1-b, .pdf
Required1-a. Determine Mahomess pension expense for 2024.1-b, .pdf
 
Relaciona cada �poca con sus caracter�sticas definitorias. Per�od.pdf
Relaciona cada �poca con sus caracter�sticas definitorias.  Per�od.pdfRelaciona cada �poca con sus caracter�sticas definitorias.  Per�od.pdf
Relaciona cada �poca con sus caracter�sticas definitorias. Per�od.pdf
 
Regarding the management of R&D teams after Vandeputte�s diversifica.pdf
Regarding the management of R&D teams after Vandeputte�s diversifica.pdfRegarding the management of R&D teams after Vandeputte�s diversifica.pdf
Regarding the management of R&D teams after Vandeputte�s diversifica.pdf
 
Reflect on your current workplace where you currently interact with .pdf
Reflect on your current workplace where you currently interact with .pdfReflect on your current workplace where you currently interact with .pdf
Reflect on your current workplace where you currently interact with .pdf
 
Reflexiona sobre un cambio profesional importante que hayas experime.pdf
Reflexiona sobre un cambio profesional importante que hayas experime.pdfReflexiona sobre un cambio profesional importante que hayas experime.pdf
Reflexiona sobre un cambio profesional importante que hayas experime.pdf
 
ReinforcementR-4.3 Viruses that perform no explicit malicious beha.pdf
ReinforcementR-4.3 Viruses that perform no explicit malicious beha.pdfReinforcementR-4.3 Viruses that perform no explicit malicious beha.pdf
ReinforcementR-4.3 Viruses that perform no explicit malicious beha.pdf
 
Required 1. prepare the Income Statement for the year ended Decembe.pdf
Required 1. prepare the Income Statement for the year ended Decembe.pdfRequired 1. prepare the Income Statement for the year ended Decembe.pdf
Required 1. prepare the Income Statement for the year ended Decembe.pdf
 
Required Designate where each of the following events would be pre.pdf
Required  Designate where each of the following events would be pre.pdfRequired  Designate where each of the following events would be pre.pdf
Required Designate where each of the following events would be pre.pdf
 
Routes of Administration The nurse is teaching clients with inflamma.pdf
Routes of Administration The nurse is teaching clients with inflamma.pdfRoutes of Administration The nurse is teaching clients with inflamma.pdf
Routes of Administration The nurse is teaching clients with inflamma.pdf
 
Renzo es un l�der entusiasta que cree en sus ideas. Renzo se detiene.pdf
Renzo es un l�der entusiasta que cree en sus ideas. Renzo se detiene.pdfRenzo es un l�der entusiasta que cree en sus ideas. Renzo se detiene.pdf
Renzo es un l�der entusiasta que cree en sus ideas. Renzo se detiene.pdf
 
Romance en la oficina buscando respuestas a tientasDescripci�n de.pdf
Romance en la oficina buscando respuestas a tientasDescripci�n de.pdfRomance en la oficina buscando respuestas a tientasDescripci�n de.pdf
Romance en la oficina buscando respuestas a tientasDescripci�n de.pdf
 
ROBOTICS Currently, roboticists and AI researchers are still strug.pdf
ROBOTICS Currently, roboticists and AI researchers are still strug.pdfROBOTICS Currently, roboticists and AI researchers are still strug.pdf
ROBOTICS Currently, roboticists and AI researchers are still strug.pdf
 
Roberts Rules of Order refer toA.procedural guidelines on the corre.pdf
Roberts Rules of Order refer toA.procedural guidelines on the corre.pdfRoberts Rules of Order refer toA.procedural guidelines on the corre.pdf
Roberts Rules of Order refer toA.procedural guidelines on the corre.pdf
 
RKO-Stanley v. GrazianoEagen, J.On April 30, 1970, RKO-Stanley W.pdf
RKO-Stanley v. GrazianoEagen, J.On April 30, 1970, RKO-Stanley W.pdfRKO-Stanley v. GrazianoEagen, J.On April 30, 1970, RKO-Stanley W.pdf
RKO-Stanley v. GrazianoEagen, J.On April 30, 1970, RKO-Stanley W.pdf
 

Kürzlich hochgeladen

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Kürzlich hochgeladen (20)

How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 

Exercises (write all 4 methods!) 1. Complete the ElevensBoard cla.pdf

  • 1. Exercises (write all 4 methods!): 1. Complete the ElevensBoard class in the A09 Starter Code folder, 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 selectedCards) 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:
  • 2. 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 selectedCards) d. containsJQK This method determines if the selected elements of cards contain 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 selectedCards) import java.util.List; import java.util.ArrayList; /** * The ElevensBoard class represents the board in a game of Elevens. */ public class ElevensBoard { /** * The size (number of cards) on the board. */ private static final int BOARD_SIZE = 9;
  • 3. /** * 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}; /** * The cards on this board. */ private Card[] cards; /** * The deck of cards being used to play the current game. */ private Deck deck; /** * Flag used to control debugging print statements. */ private static final boolean I_AM_DEBUGGING = false; /** * Creates a new ElevensBoard instance. */ public ElevensBoard() { cards = new Card[BOARD_SIZE]; deck = new Deck(RANKS, SUITS, POINT_VALUES); if (I_AM_DEBUGGING) {
  • 4. System.out.println(deck); System.out.println("----------"); } dealMyCards(); } /** * Start a new game by shuffling the deck and * dealing some cards to this board. */ public void newGame() { deck.shuffle(); dealMyCards(); } /** * Accesses the size of the board. * Note that this is not the number of cards it contains, * which will be smaller near the end of a winning game. * @return the size of the board */ public int size() { return cards.length; } /** * Determines if the board is empty (has no cards). * @return true if this board is empty; false otherwise. */ public boolean isEmpty() { for (int k = 0; k < cards.length; k++) { if (cards[k] != null) { return false; } } return true; } /** * Deal a card to the kth position in this board.
  • 5. * If the deck is empty, the kth card is set to null. * @param k the index of the card to be dealt. */ public void deal(int k) { cards[k] = deck.deal(); } /** * Accesses the deck's size. * @return the number of undealt cards left in the deck. */ public int deckSize() { return deck.size(); } /** * Accesses a card on the board. * @return the card at position k on the board. * @param k is the board position of the card to return. */ public Card cardAt(int k) { return cards[k]; } /** * Replaces selected cards on the board by dealing new cards. * @param selectedCards is a list of the indices of the * cards to be replaced. */ public void replaceSelectedCards(List selectedCards) { for (Integer k : selectedCards) { deal(k.intValue()); } } /** * Gets the indexes of the actual (non-null) cards on the board. * * @return a List that contains the locations (indexes) * of the non-null entries on the board.
  • 6. */ public List cardIndexes() { List selected = new ArrayList(); for (int k = 0; k < cards.length; k++) { if (cards[k] != null) { selected.add(new Integer(k)); } } return selected; } /** * Generates and returns a string representation of this board. * @return the string version of this board. */ public String toString() { String s = ""; for (int k = 0; k < cards.length; k++) { s = s + k + ": " + cards[k] + "n"; } return s; } /** * Determine whether or not the game has been won, * i.e. neither the board nor the deck has any more cards. * @return true when the current game has been won; * false otherwise. */ public boolean gameIsWon() { if (deck.isEmpty()) { for (Card c : cards) { if (c != null) { return false; } } return true; }
  • 7. return false; } /** * 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. */ public boolean isLegal(List selectedCards) { /* *** TO BE IMPLEMENTED IN ACTIVITY 9 *** */ } /** * 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. */ public boolean anotherPlayIsPossible() { /* *** TO BE IMPLEMENTED IN ACTIVITY 9 *** */ } /** * Deal cards to this board to start the game. */ private void dealMyCards() { for (int k = 0; k < cards.length; k++) { cards[k] = deck.deal(); } } /** * Check for an 11-pair in the selected cards.
  • 8. * @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 selectedCards) { /* *** TO BE IMPLEMENTED IN ACTIVITY 9 *** */ } /** * 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 selectedCards) { /* *** TO BE IMPLEMENTED IN ACTIVITY 9 *** */ } }