SlideShare a Scribd company logo
1 of 8
Download to read offline
Introduction:
Now that the Card and Deck classes are completed, the next class to design is ElevensBoard.
This class will contain the state (instance variables) and behavior (methods) necessary to play
the game of Elevens.
Here's the code:
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 *** */
}
}
Use complete sentences, and write at an AP level.
Explain your answers.
Questions:
1. What items would be necessary if you were playing a game of Elevens at your desk
(not on the computer)? List the private instance variables needed for the ElevensBoard class.
2. Write an algorithm (in English not java, 1 step per line) that describes the actions necessary to
play the Elevens game.
3. Now examine the partially implemented ElevensBoard.java file found in the Activity 07
Starter Code directory.
Does the ElevensBoard class contain all the state and behavior necessary to play the game?
4. ElevensBoard.java contains three helper methods. These helper methods are private because
they are only called from the ElevensBoard class.
4a. Where is the dealMyCards method called in ElevensBoard?
4b. Which public methods should call the containsPairSum11 and containsJQK methods?
4c. Its important to understand how the cardIndexes method works, and how the list that it
returns is used.
Suppose that cards contains the elements shown below.
Trace the execution of the cardIndexes method to determine what list will be returned.
Complete the diagram below by filling in the elements of the returned list,
and by showing how those values index cards.
Note that the returned list may have less than 9 elements.
0 1 2 3 4 5 6 7 8
cards -> J 6 null 2 null null A 4 null
0 1 2 3 4 5 6 7 8
returned list ->
4d. Complete the following printCards method to print all of the elements of cards that are
indexed by cIndexes.
public static printCards(ElevensBoard board) {
List cIndexes = board.cardIndexes();
/* Your code goes here. */
}
4e. Which one of the methods that you identified in question 4b above needs to call the
cardIndexes method before calling the containsPairSum11 and containsJQK methods? Why?

More Related Content

Similar to Introduction Now that the Card and Deck classes are completed, th.pdf

Complete in JavaCardApp.javapublic class CardApp { private.pdf
Complete in JavaCardApp.javapublic class CardApp {   private.pdfComplete in JavaCardApp.javapublic class CardApp {   private.pdf
Complete in JavaCardApp.javapublic class CardApp { private.pdfMAYANKBANSAL1981
 
QuestionProblem 1 In a source file carddeck.cpp, provide an impl.pdf
QuestionProblem 1 In a source file carddeck.cpp, provide an impl.pdfQuestionProblem 1 In a source file carddeck.cpp, provide an impl.pdf
QuestionProblem 1 In a source file carddeck.cpp, provide an impl.pdffootstatus
 
project 6cards.pyimport randomclass Card( object ).docx
project 6cards.pyimport randomclass Card( object ).docxproject 6cards.pyimport randomclass Card( object ).docx
project 6cards.pyimport randomclass Card( object ).docxbriancrawford30935
 
blackjackrevised2BlackJack.hBLACKJACK#ifndef _BLACKJA.docx
blackjackrevised2BlackJack.hBLACKJACK#ifndef _BLACKJA.docxblackjackrevised2BlackJack.hBLACKJACK#ifndef _BLACKJA.docx
blackjackrevised2BlackJack.hBLACKJACK#ifndef _BLACKJA.docxAASTHA76
 
Exercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdf
Exercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdfExercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdf
Exercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdffms12345
 
Write a class that maintains the top ten scores for a game application.pdf
Write a class that maintains the top ten scores for a game application.pdfWrite a class that maintains the top ten scores for a game application.pdf
Write a class that maintains the top ten scores for a game application.pdfastrading2
 
import javautilLinkedList import javautilQueue import .pdf
import javautilLinkedList import javautilQueue import .pdfimport javautilLinkedList import javautilQueue import .pdf
import javautilLinkedList import javautilQueue import .pdfADITIEYEWEAR
 
Can someone help me setup this in JAVA Im new to java. Thanks.pdf
Can someone help me setup this in JAVA Im new to java. Thanks.pdfCan someone help me setup this in JAVA Im new to java. Thanks.pdf
Can someone help me setup this in JAVA Im new to java. Thanks.pdfjeeteshmalani1
 
This is the final code which meets your requirement.Than youCard.j.pdf
This is the final code which meets your requirement.Than youCard.j.pdfThis is the final code which meets your requirement.Than youCard.j.pdf
This is the final code which meets your requirement.Than youCard.j.pdfaplolomedicalstoremr
 

Similar to Introduction Now that the Card and Deck classes are completed, th.pdf (10)

Complete in JavaCardApp.javapublic class CardApp { private.pdf
Complete in JavaCardApp.javapublic class CardApp {   private.pdfComplete in JavaCardApp.javapublic class CardApp {   private.pdf
Complete in JavaCardApp.javapublic class CardApp { private.pdf
 
QuestionProblem 1 In a source file carddeck.cpp, provide an impl.pdf
QuestionProblem 1 In a source file carddeck.cpp, provide an impl.pdfQuestionProblem 1 In a source file carddeck.cpp, provide an impl.pdf
QuestionProblem 1 In a source file carddeck.cpp, provide an impl.pdf
 
project 6cards.pyimport randomclass Card( object ).docx
project 6cards.pyimport randomclass Card( object ).docxproject 6cards.pyimport randomclass Card( object ).docx
project 6cards.pyimport randomclass Card( object ).docx
 
blackjackrevised2BlackJack.hBLACKJACK#ifndef _BLACKJA.docx
blackjackrevised2BlackJack.hBLACKJACK#ifndef _BLACKJA.docxblackjackrevised2BlackJack.hBLACKJACK#ifndef _BLACKJA.docx
blackjackrevised2BlackJack.hBLACKJACK#ifndef _BLACKJA.docx
 
Exercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdf
Exercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdfExercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdf
Exercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdf
 
Write a class that maintains the top ten scores for a game application.pdf
Write a class that maintains the top ten scores for a game application.pdfWrite a class that maintains the top ten scores for a game application.pdf
Write a class that maintains the top ten scores for a game application.pdf
 
import javautilLinkedList import javautilQueue import .pdf
import javautilLinkedList import javautilQueue import .pdfimport javautilLinkedList import javautilQueue import .pdf
import javautilLinkedList import javautilQueue import .pdf
 
Can someone help me setup this in JAVA Im new to java. Thanks.pdf
Can someone help me setup this in JAVA Im new to java. Thanks.pdfCan someone help me setup this in JAVA Im new to java. Thanks.pdf
Can someone help me setup this in JAVA Im new to java. Thanks.pdf
 
This is the final code which meets your requirement.Than youCard.j.pdf
This is the final code which meets your requirement.Than youCard.j.pdfThis is the final code which meets your requirement.Than youCard.j.pdf
This is the final code which meets your requirement.Than youCard.j.pdf
 
#include deck.h .pdf
#include deck.h .pdf#include deck.h .pdf
#include deck.h .pdf
 

More from charanjit1717

Is it possible to register Dinosaurs as a mark for a fast food res.pdf
Is it possible to register Dinosaurs as a mark for a fast food res.pdfIs it possible to register Dinosaurs as a mark for a fast food res.pdf
Is it possible to register Dinosaurs as a mark for a fast food res.pdfcharanjit1717
 
Internal sex organs The internal (S.....x organs), describe them..pdf
Internal sex organs The internal (S.....x organs), describe them..pdfInternal sex organs The internal (S.....x organs), describe them..pdf
Internal sex organs The internal (S.....x organs), describe them..pdfcharanjit1717
 
Interview TWO consumers who have used sharing economy service, such .pdf
Interview TWO consumers who have used sharing economy service, such .pdfInterview TWO consumers who have used sharing economy service, such .pdf
Interview TWO consumers who have used sharing economy service, such .pdfcharanjit1717
 
is 0.1 less than 0.51 Nonreactive SCO Nonreactive Nonreactive SC.pdf
is 0.1 less than 0.51  Nonreactive SCO Nonreactive Nonreactive SC.pdfis 0.1 less than 0.51  Nonreactive SCO Nonreactive Nonreactive SC.pdf
is 0.1 less than 0.51 Nonreactive SCO Nonreactive Nonreactive SC.pdfcharanjit1717
 
Is it morally justifiable to use a denial-of-service attack to shut .pdf
Is it morally justifiable to use a denial-of-service attack to shut .pdfIs it morally justifiable to use a denial-of-service attack to shut .pdf
Is it morally justifiable to use a denial-of-service attack to shut .pdfcharanjit1717
 
Interpret the part of Figure 2A that refers to Clusia in the dry sea.pdf
Interpret the part of Figure 2A that refers to Clusia in the dry sea.pdfInterpret the part of Figure 2A that refers to Clusia in the dry sea.pdf
Interpret the part of Figure 2A that refers to Clusia in the dry sea.pdfcharanjit1717
 
Investigue la historia de Enron. Hablar de la empresa. �Que hici.pdf
Investigue la historia de Enron. Hablar de la empresa. �Que hici.pdfInvestigue la historia de Enron. Hablar de la empresa. �Que hici.pdf
Investigue la historia de Enron. Hablar de la empresa. �Que hici.pdfcharanjit1717
 
Internal control systems areA. Developed by the Securities and Ex.pdf
Internal control systems areA. Developed by the Securities and Ex.pdfInternal control systems areA. Developed by the Securities and Ex.pdf
Internal control systems areA. Developed by the Securities and Ex.pdfcharanjit1717
 
Instrucciones Contesta las preguntas en oraciones completas. Trate .pdf
Instrucciones Contesta las preguntas en oraciones completas. Trate .pdfInstrucciones Contesta las preguntas en oraciones completas. Trate .pdf
Instrucciones Contesta las preguntas en oraciones completas. Trate .pdfcharanjit1717
 
Investigue un poco y describa dos o tres escenarios en los que ser�a.pdf
Investigue un poco y describa dos o tres escenarios en los que ser�a.pdfInvestigue un poco y describa dos o tres escenarios en los que ser�a.pdf
Investigue un poco y describa dos o tres escenarios en los que ser�a.pdfcharanjit1717
 
Investigue un poco sobre los proveedores de nube personal. �Qu� ti.pdf
Investigue un poco sobre los proveedores de nube personal. �Qu� ti.pdfInvestigue un poco sobre los proveedores de nube personal. �Qu� ti.pdf
Investigue un poco sobre los proveedores de nube personal. �Qu� ti.pdfcharanjit1717
 
Investigate the five core missions of DHS and discuss how they promo.pdf
Investigate the five core missions of DHS and discuss how they promo.pdfInvestigate the five core missions of DHS and discuss how they promo.pdf
Investigate the five core missions of DHS and discuss how they promo.pdfcharanjit1717
 
Innovation Brewing of Sylva filed a trademark application for the co.pdf
Innovation Brewing of Sylva filed a trademark application for the co.pdfInnovation Brewing of Sylva filed a trademark application for the co.pdf
Innovation Brewing of Sylva filed a trademark application for the co.pdfcharanjit1717
 
Instructions1. Create a title slide deck that must include your.pdf
Instructions1. Create a title slide deck that must include your.pdfInstructions1. Create a title slide deck that must include your.pdf
Instructions1. Create a title slide deck that must include your.pdfcharanjit1717
 
INTRODUCCI�N Koss Corporation es una empresa de Milwaukee cuyo negoc.pdf
INTRODUCCI�N Koss Corporation es una empresa de Milwaukee cuyo negoc.pdfINTRODUCCI�N Koss Corporation es una empresa de Milwaukee cuyo negoc.pdf
INTRODUCCI�N Koss Corporation es una empresa de Milwaukee cuyo negoc.pdfcharanjit1717
 
Introduction William Clay Ford, Jr., was staring out the window of.pdf
Introduction William Clay Ford, Jr., was staring out the window of.pdfIntroduction William Clay Ford, Jr., was staring out the window of.pdf
Introduction William Clay Ford, Jr., was staring out the window of.pdfcharanjit1717
 
Intro to ProgrammingExercise 1University_Athletics.pyMake a cl.pdf
Intro to ProgrammingExercise 1University_Athletics.pyMake a cl.pdfIntro to ProgrammingExercise 1University_Athletics.pyMake a cl.pdf
Intro to ProgrammingExercise 1University_Athletics.pyMake a cl.pdfcharanjit1717
 
International MARCOM fails and WhyConsider the International Mark.pdf
International MARCOM fails and WhyConsider the International Mark.pdfInternational MARCOM fails and WhyConsider the International Mark.pdf
International MARCOM fails and WhyConsider the International Mark.pdfcharanjit1717
 
International Fisher Effect suggests thatGroup of answer choices.pdf
International Fisher Effect suggests thatGroup of answer choices.pdfInternational Fisher Effect suggests thatGroup of answer choices.pdf
International Fisher Effect suggests thatGroup of answer choices.pdfcharanjit1717
 
Interiores de galaxiasEstado de Resultados 2011 ($ en Millones) .pdf
Interiores de galaxiasEstado de Resultados 2011 ($ en Millones) .pdfInteriores de galaxiasEstado de Resultados 2011 ($ en Millones) .pdf
Interiores de galaxiasEstado de Resultados 2011 ($ en Millones) .pdfcharanjit1717
 

More from charanjit1717 (20)

Is it possible to register Dinosaurs as a mark for a fast food res.pdf
Is it possible to register Dinosaurs as a mark for a fast food res.pdfIs it possible to register Dinosaurs as a mark for a fast food res.pdf
Is it possible to register Dinosaurs as a mark for a fast food res.pdf
 
Internal sex organs The internal (S.....x organs), describe them..pdf
Internal sex organs The internal (S.....x organs), describe them..pdfInternal sex organs The internal (S.....x organs), describe them..pdf
Internal sex organs The internal (S.....x organs), describe them..pdf
 
Interview TWO consumers who have used sharing economy service, such .pdf
Interview TWO consumers who have used sharing economy service, such .pdfInterview TWO consumers who have used sharing economy service, such .pdf
Interview TWO consumers who have used sharing economy service, such .pdf
 
is 0.1 less than 0.51 Nonreactive SCO Nonreactive Nonreactive SC.pdf
is 0.1 less than 0.51  Nonreactive SCO Nonreactive Nonreactive SC.pdfis 0.1 less than 0.51  Nonreactive SCO Nonreactive Nonreactive SC.pdf
is 0.1 less than 0.51 Nonreactive SCO Nonreactive Nonreactive SC.pdf
 
Is it morally justifiable to use a denial-of-service attack to shut .pdf
Is it morally justifiable to use a denial-of-service attack to shut .pdfIs it morally justifiable to use a denial-of-service attack to shut .pdf
Is it morally justifiable to use a denial-of-service attack to shut .pdf
 
Interpret the part of Figure 2A that refers to Clusia in the dry sea.pdf
Interpret the part of Figure 2A that refers to Clusia in the dry sea.pdfInterpret the part of Figure 2A that refers to Clusia in the dry sea.pdf
Interpret the part of Figure 2A that refers to Clusia in the dry sea.pdf
 
Investigue la historia de Enron. Hablar de la empresa. �Que hici.pdf
Investigue la historia de Enron. Hablar de la empresa. �Que hici.pdfInvestigue la historia de Enron. Hablar de la empresa. �Que hici.pdf
Investigue la historia de Enron. Hablar de la empresa. �Que hici.pdf
 
Internal control systems areA. Developed by the Securities and Ex.pdf
Internal control systems areA. Developed by the Securities and Ex.pdfInternal control systems areA. Developed by the Securities and Ex.pdf
Internal control systems areA. Developed by the Securities and Ex.pdf
 
Instrucciones Contesta las preguntas en oraciones completas. Trate .pdf
Instrucciones Contesta las preguntas en oraciones completas. Trate .pdfInstrucciones Contesta las preguntas en oraciones completas. Trate .pdf
Instrucciones Contesta las preguntas en oraciones completas. Trate .pdf
 
Investigue un poco y describa dos o tres escenarios en los que ser�a.pdf
Investigue un poco y describa dos o tres escenarios en los que ser�a.pdfInvestigue un poco y describa dos o tres escenarios en los que ser�a.pdf
Investigue un poco y describa dos o tres escenarios en los que ser�a.pdf
 
Investigue un poco sobre los proveedores de nube personal. �Qu� ti.pdf
Investigue un poco sobre los proveedores de nube personal. �Qu� ti.pdfInvestigue un poco sobre los proveedores de nube personal. �Qu� ti.pdf
Investigue un poco sobre los proveedores de nube personal. �Qu� ti.pdf
 
Investigate the five core missions of DHS and discuss how they promo.pdf
Investigate the five core missions of DHS and discuss how they promo.pdfInvestigate the five core missions of DHS and discuss how they promo.pdf
Investigate the five core missions of DHS and discuss how they promo.pdf
 
Innovation Brewing of Sylva filed a trademark application for the co.pdf
Innovation Brewing of Sylva filed a trademark application for the co.pdfInnovation Brewing of Sylva filed a trademark application for the co.pdf
Innovation Brewing of Sylva filed a trademark application for the co.pdf
 
Instructions1. Create a title slide deck that must include your.pdf
Instructions1. Create a title slide deck that must include your.pdfInstructions1. Create a title slide deck that must include your.pdf
Instructions1. Create a title slide deck that must include your.pdf
 
INTRODUCCI�N Koss Corporation es una empresa de Milwaukee cuyo negoc.pdf
INTRODUCCI�N Koss Corporation es una empresa de Milwaukee cuyo negoc.pdfINTRODUCCI�N Koss Corporation es una empresa de Milwaukee cuyo negoc.pdf
INTRODUCCI�N Koss Corporation es una empresa de Milwaukee cuyo negoc.pdf
 
Introduction William Clay Ford, Jr., was staring out the window of.pdf
Introduction William Clay Ford, Jr., was staring out the window of.pdfIntroduction William Clay Ford, Jr., was staring out the window of.pdf
Introduction William Clay Ford, Jr., was staring out the window of.pdf
 
Intro to ProgrammingExercise 1University_Athletics.pyMake a cl.pdf
Intro to ProgrammingExercise 1University_Athletics.pyMake a cl.pdfIntro to ProgrammingExercise 1University_Athletics.pyMake a cl.pdf
Intro to ProgrammingExercise 1University_Athletics.pyMake a cl.pdf
 
International MARCOM fails and WhyConsider the International Mark.pdf
International MARCOM fails and WhyConsider the International Mark.pdfInternational MARCOM fails and WhyConsider the International Mark.pdf
International MARCOM fails and WhyConsider the International Mark.pdf
 
International Fisher Effect suggests thatGroup of answer choices.pdf
International Fisher Effect suggests thatGroup of answer choices.pdfInternational Fisher Effect suggests thatGroup of answer choices.pdf
International Fisher Effect suggests thatGroup of answer choices.pdf
 
Interiores de galaxiasEstado de Resultados 2011 ($ en Millones) .pdf
Interiores de galaxiasEstado de Resultados 2011 ($ en Millones) .pdfInteriores de galaxiasEstado de Resultados 2011 ($ en Millones) .pdf
Interiores de galaxiasEstado de Resultados 2011 ($ en Millones) .pdf
 

Recently uploaded

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 

Recently uploaded (20)

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 

Introduction Now that the Card and Deck classes are completed, th.pdf

  • 1. Introduction: Now that the Card and Deck classes are completed, the next class to design is ElevensBoard. This class will contain the state (instance variables) and behavior (methods) necessary to play the game of Elevens. Here's the code: 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;
  • 2. /** * 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() {
  • 3. 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];
  • 4. } /** * 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;
  • 5. } /** * 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;
  • 6. * 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 *** */ }
  • 7. } Use complete sentences, and write at an AP level. Explain your answers. Questions: 1. What items would be necessary if you were playing a game of Elevens at your desk (not on the computer)? List the private instance variables needed for the ElevensBoard class. 2. Write an algorithm (in English not java, 1 step per line) that describes the actions necessary to play the Elevens game. 3. Now examine the partially implemented ElevensBoard.java file found in the Activity 07 Starter Code directory. Does the ElevensBoard class contain all the state and behavior necessary to play the game? 4. ElevensBoard.java contains three helper methods. These helper methods are private because they are only called from the ElevensBoard class. 4a. Where is the dealMyCards method called in ElevensBoard? 4b. Which public methods should call the containsPairSum11 and containsJQK methods? 4c. Its important to understand how the cardIndexes method works, and how the list that it returns is used. Suppose that cards contains the elements shown below. Trace the execution of the cardIndexes method to determine what list will be returned. Complete the diagram below by filling in the elements of the returned list, and by showing how those values index cards. Note that the returned list may have less than 9 elements. 0 1 2 3 4 5 6 7 8 cards -> J 6 null 2 null null A 4 null 0 1 2 3 4 5 6 7 8 returned list ->
  • 8. 4d. Complete the following printCards method to print all of the elements of cards that are indexed by cIndexes. public static printCards(ElevensBoard board) { List cIndexes = board.cardIndexes(); /* Your code goes here. */ } 4e. Which one of the methods that you identified in question 4b above needs to call the cardIndexes method before calling the containsPairSum11 and containsJQK methods? Why?