From e49f0f265e86cc8eee03559cedbb56fb601dbd7e Mon Sep 17 00:00:00 2001 From: Tim Padjen Date: Fri, 4 Mar 2016 08:20:32 -0700 Subject: [PATCH 1/9] Add answers file --- answers.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 answers.md diff --git a/answers.md b/answers.md new file mode 100644 index 0000000..e69de29 From b7f03bf9ea2c521b713a82b4e59fb1a31104d082 Mon Sep 17 00:00:00 2001 From: Tim Padjen Date: Fri, 4 Mar 2016 08:28:57 -0700 Subject: [PATCH 2/9] Add starter code --- src/Card.java | 92 +++++++++++++++++++++++++++++++++++++++ src/Deck.java | 104 ++++++++++++++++++++++++++++++++++++++++++++ src/DeckTester.java | 13 ++++++ 3 files changed, 209 insertions(+) create mode 100644 src/Card.java create mode 100644 src/Deck.java create mode 100644 src/DeckTester.java diff --git a/src/Card.java b/src/Card.java new file mode 100644 index 0000000..67ef394 --- /dev/null +++ b/src/Card.java @@ -0,0 +1,92 @@ +/** + * Card.java + * + * Card represents a playing card. + */ +public class Card { + + /** + * String value that holds the suit of the card + */ + private String suit; + + /** + * String value that holds the rank of the card + */ + private String rank; + + /** + * int value that holds the point value. + */ + private int pointValue; + + + /** + * Creates a new Card instance. + * + * @param cardRank a String value + * containing the rank of the card + * @param cardSuit a String value + * containing the suit of the card + * @param cardPointValue an int value + * containing the point value of the card + */ + public Card(String cardRank, String cardSuit, int cardPointValue) { + //initializes a new Card with the given rank, suit, and point value + rank = cardRank; + suit = cardSuit; + pointValue = cardPointValue; + } + + + /** + * Accesses this Card's suit. + * @return this Card's suit. + */ + public String suit() { + return suit; + } + + /** + * Accesses this Card's rank. + * @return this Card's rank. + */ + public String rank() { + return rank; + } + + /** + * Accesses this Card's point value. + * @return this Card's point value. + */ + public int pointValue() { + return pointValue; + } + + /** Compare this card with the argument. + * @param otherCard the other card to compare to this + * @return true if the rank, suit, and point value of this card + * are equal to those of the argument; + * false otherwise. + */ + public boolean matches(Card otherCard) { + return otherCard.suit().equals(this.suit()) + && otherCard.rank().equals(this.rank()) + && otherCard.pointValue() == this.pointValue(); + } + + /** + * Converts the rank, suit, and point value into a string in the format + * "[Rank] of [Suit] (point value = [PointValue])". + * This provides a useful way of printing the contents + * of a Deck in an easily readable format or performing + * other similar functions. + * + * @return a String containing the rank, suit, + * and point value of the card. + */ + @Override + public String toString() { + return rank + " of " + suit + " (point value = " + pointValue + ")"; + } +} diff --git a/src/Deck.java b/src/Deck.java new file mode 100644 index 0000000..8713f14 --- /dev/null +++ b/src/Deck.java @@ -0,0 +1,104 @@ +import java.util.List; +import java.util.ArrayList; + +/** + * The Deck class represents a shuffled deck of cards. + * It provides several operations including + * initialize, shuffle, deal, and check if empty. + */ +public class Deck { + + /** + * cards contains all the cards in the deck. + */ + private List cards; + + /** + * size is the number of not-yet-dealt cards. + * Cards are dealt from the top (highest index) down. + * The next card to be dealt is at size - 1. + */ + private int size; + + + /** + * Creates a new Deck instance.
+ * It pairs each element of ranks with each element of suits, + * and produces one of the corresponding card. + * @param ranks is an array containing all of the card ranks. + * @param suits is an array containing all of the card suits. + * @param values is an array containing all of the card point values. + */ + public Deck(String[] ranks, String[] suits, int[] values) { + /* *** TO BE IMPLEMENTED IN ACTIVITY 2 *** */ + } + + + /** + * Determines if this deck is empty (no undealt cards). + * @return true if this deck is empty, false otherwise. + */ + public boolean isEmpty() { + /* *** TO BE IMPLEMENTED IN ACTIVITY 2 *** */ + } + + /** + * Accesses the number of undealt cards in this deck. + * @return the number of undealt cards in this deck. + */ + public int size() { + /* *** TO BE IMPLEMENTED IN ACTIVITY 2 *** */ + } + + /** + * Randomly permute the given collection of cards + * and reset the size to represent the entire deck. + */ + public void shuffle() { + /* *** TO BE IMPLEMENTED IN ACTIVITY 4 *** */ + } + + /** + * Deals a card from this deck. + * @return the card just dealt, or null if all the cards have been + * previously dealt. + */ + public Card deal() { + /* *** TO BE IMPLEMENTED IN ACTIVITY 2 *** */ + } + + /** + * Generates and returns a string representation of this deck. + * @return a string representation of this deck. + */ + @Override + public String toString() { + String rtn = "size = " + size + "\nUndealt cards: \n"; + + for (int k = size - 1; k >= 0; k--) { + rtn = rtn + cards.get(k); + if (k != 0) { + rtn = rtn + ", "; + } + if ((size - k) % 2 == 0) { + // Insert carriage returns so entire deck is visible on console. + rtn = rtn + "\n"; + } + } + + rtn = rtn + "\nDealt cards: \n"; + for (int k = cards.size() - 1; k >= size; k--) { + rtn = rtn + cards.get(k); + if (k != size) { + rtn = rtn + ", "; + } + if ((k - cards.size()) % 2 == 0) { + // Insert carriage returns so entire deck is visible on console. + rtn = rtn + "\n"; + } + } + + rtn = rtn + "\n"; + return rtn; + } +} diff --git a/src/DeckTester.java b/src/DeckTester.java new file mode 100644 index 0000000..4201fc3 --- /dev/null +++ b/src/DeckTester.java @@ -0,0 +1,13 @@ +/** + * This is a class that tests the Deck class. + */ +public class DeckTester { + + /** + * The main method in this class checks the Deck operations for consistency. + * @param args is not used. + */ + public static void main(String[] args) { + /* *** TO BE IMPLEMENTED IN ACTIVITY 2 *** */ + } +} From f7a40d780fc33de62e76a51caa1198c191ee37b8 Mon Sep 17 00:00:00 2001 From: Tim Padjen Date: Fri, 4 Mar 2016 09:58:45 -0700 Subject: [PATCH 3/9] Add fetch step before creating new activity branch --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index c852477..81e3194 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ $ git remote add upstream https://github.com/mvhs-apcs/Elevens.git Then create a branch that tracks with the original repo's activity 1 branch: ``` +$ git fetch upstream a1 $ git checkout -b a1 upstream/a1 ``` @@ -35,5 +36,6 @@ The activities have not all been pushed at the start of the lab because each act To move to the next activity, show your completed solution to your instructor. He will then push a branch for you to use for the next activity. The branch name will be formatted like this: `-a#`. For example, Abe Lincoln would move to activity 4 with this command: ``` +$ git fetch upstream four_score-a4 $ git checkout -b a4 upstream/four_score-a4 ``` \ No newline at end of file From 1feb2e8ccbdfda540ac2f8eb9f0438e19eb907ca Mon Sep 17 00:00:00 2001 From: Tim Padjen Date: Mon, 27 Mar 2017 11:50:01 -0600 Subject: [PATCH 4/9] Update classpath to jre 1.8 --- .classpath | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.classpath b/.classpath index fceb480..62e1b08 100644 --- a/.classpath +++ b/.classpath @@ -1,6 +1,6 @@ - + From 6ddb4d77286cc21f5119eefbf4b58e535a75fd18 Mon Sep 17 00:00:00 2001 From: Tim Padjen Date: Wed, 11 Mar 2020 08:32:41 -0600 Subject: [PATCH 5/9] Update branch fetching instructions --- README.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 81e3194..0d20e44 100644 --- a/README.md +++ b/README.md @@ -32,10 +32,14 @@ $ git push origin a# ## Switching to the next activity -The activities have not all been pushed at the start of the lab because each activity builds on the next and sometimes has working versions of the problems from the previous activities. +### Activities 1-5 -To move to the next activity, show your completed solution to your instructor. He will then push a branch for you to use for the next activity. The branch name will be formatted like this: `-a#`. For example, Abe Lincoln would move to activity 4 with this command: +### Later Activities + +The remaining activities have not all been pushed because each activity builds on the next. Sometimes activities have working versions of the problems from the previous activities. + +To move to the next activity, show your completed solution to your instructor. He will then push a branch for you to use for the next activity. The branch name will be formatted like this: `-a#`. For example, Abe Lincoln would move to activity 6 with this command: ``` -$ git fetch upstream four_score-a4 -$ git checkout -b a4 upstream/four_score-a4 +$ git fetch upstream four_score-a6 +$ git checkout -b a6 upstream/four_score-a6 ``` \ No newline at end of file From c2521a215f428d7523731602a38497b255616eaf Mon Sep 17 00:00:00 2001 From: Tim Padjen Date: Wed, 11 Mar 2020 08:38:34 -0600 Subject: [PATCH 6/9] Update a1-5 fetching commands --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 0d20e44..26ef96b 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,13 @@ $ git push origin a# ### Activities 1-5 +Change the # to the number of the activity you want to grab. + +``` +$ git fetch upstream a# +$ git checkout -b a# upstream/a# +``` + ### Later Activities The remaining activities have not all been pushed because each activity builds on the next. Sometimes activities have working versions of the problems from the previous activities. From 51a975e3bc6946551184feab831798c6b4d96fc8 Mon Sep 17 00:00:00 2001 From: Tim Padjen Date: Mon, 23 Mar 2020 12:12:32 -0600 Subject: [PATCH 7/9] Remove unnecessary config files --- .classpath | 6 ------ .project | 17 ----------------- 2 files changed, 23 deletions(-) delete mode 100644 .classpath delete mode 100644 .project diff --git a/.classpath b/.classpath deleted file mode 100644 index 62e1b08..0000000 --- a/.classpath +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/.project b/.project deleted file mode 100644 index 0365963..0000000 --- a/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - Elevens - - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - - From 1fe8c220b5b3ee1bed0b6648c27c84b597aeee11 Mon Sep 17 00:00:00 2001 From: Tim Padjen Date: Mon, 23 Mar 2020 12:17:41 -0600 Subject: [PATCH 8/9] Ignore .project file --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 8c9a6ec..702c1c2 100644 --- a/.gitignore +++ b/.gitignore @@ -76,4 +76,6 @@ $RECYCLE.BIN/ *.msp # Windows shortcuts -*.lnk \ No newline at end of file +*.lnk + +.project From dd2e38a1b64e48a2db9e860ab4d1b6f7b3ec4a6a Mon Sep 17 00:00:00 2001 From: Cassidy Christian Date: Wed, 25 Mar 2020 20:47:16 -0600 Subject: [PATCH 9/9] Add Activity 2 --- answers.md | 24 ++++++++++++++++++++++++ src/Deck.java | 26 ++++++++++++++++++++++++++ src/DeckTester.java | 24 ++++++++++++++++++++++++ 3 files changed, 74 insertions(+) diff --git a/answers.md b/answers.md index e69de29..56cccc4 100644 --- a/answers.md +++ b/answers.md @@ -0,0 +1,24 @@ +1. Explain in your own words the relationship between a deck and a card. +Cards make up the components of the deck. The deck is an arraylist of cards. In a single deck, there will be 52 cards. A card can be by itself, but for a deck to exist, there must be multiple cards. + +2. Consider the deck initialized with the statements below. How many cards does the deck contain? + String[] ranks = {"jack", "queen", "king"}; + String[] suits = {"blue", "red"}; + int[] pointValues = {11, 12, 13}; + Deck d = new Deck(ranks, suits, pointValues); + +From the looks of it, the programmer was planning to create three separate cards. However, the fact there are only two suits, instead of three to correlate with the number of ranks and point values, would cause an index out of bounds error. Right now, there would be no cards in the deck because the code would not be able to compile. In order for the code to run, the programmer would need to add another cell to the suit array for the command line to say there are three separate cards. + +3. The game of Twenty-One is played with a deck of 52 cards. Ranks run from ac (highest) down to 2 (lowest). Suits are spades, hearts, diamonds, and clubs as in many other games. A face card has point value 10; an ace has point value 11; point values for 2, …, 10 are 2, …, 10, respectively. Specify the +contents of the ranks, suits, and pointValues arrays so that the statement: + Deck d = new Deck(ranks, suits, pointValues); +initializes a deck for a Twenty-One game. + +String[] ranks = {“2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”, “10”, “Jack”, “Queen”, “King”, “Ace”}; +String[] suits = {“Spades”, “Diamonds”, “Clubs”, “Hearts”}; +int [] pointValues = {2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 11}; + +4. Does the order of elements of the ranks, suits, and pointValues arrays matter? +Yes! The order of elements of the ranks, suits, and pointValues arrays do matter! The cells correlate with each other. All the information in cell 0 for ranks, suits, and pointValues would make one specific card. The programmer needs to make a pattern with the arrays to create the cards that he or she wants. + +It might not matter as much when the user is first initializing the information. However, the cells for sure need to correlate when we are testing our code. \ No newline at end of file diff --git a/src/Deck.java b/src/Deck.java index 8713f14..6f4c563 100644 --- a/src/Deck.java +++ b/src/Deck.java @@ -31,6 +31,17 @@ public class Deck { */ public Deck(String[] ranks, String[] suits, int[] values) { /* *** TO BE IMPLEMENTED IN ACTIVITY 2 *** */ + this.cards= new ArrayList(); + for(int i=0;i