CS XXXXXXXXXXAsst 2Assignment 2 CS 1027 Computer Science Fundamentals II Due date: Monday, February 27 at 11:55 pm Learning Outcomes In this assignment, you will get practice...

1 answer below »
Can you do this assignment in Java code?


CS 1027 - Asst 2 Assignment 2 CS 1027 Computer Science Fundamentals II Due date: Monday, February 27 at 11:55 pm Learning Outcomes In this assignment, you will get practice with:  Creating collections that work for generic types  Problem solving using sets and power sets  Working with linked lists  Using loops and conditionals  Programming according to specifications Introduction Cribbage is an old, but still popular, card game using a standard 52-card deck in which each player has a hand of 4 cards. There is also one card from the remainder of the deck that is flipped and used by all players – this card is called the "starter". There are two phases in each round of the game: the pegging phase and the counting phase. We will focus on the counting phase only. In the counting phase, each player will count the number of points they should receive from their 4 cards plus with the communal starter card. There are a variety of ways to score points in this phase of Cribbage: Pairs, Runs, Fifteen, Flush, and His Knobs. Each of these categories is described with examples below. Scoring can occur from any number of these categories and the total number of points includes points from all these categories. Each card has two properties: its suit and its rank. The suit is the red or black symbol on the card: Hearts, Diamonds, Clubs, or Spades. The rank is the value of the card's number or letter. Most cards have a number from 2 to 10 and their rank is equal to that numeric value. Some cards have a letter instead of a number; i.e. A, J, Q, or K. The A (ace) has a rank of 1, J (jack) has a rank of 11, Q (queen) has a rank of 12, and K (king) has a rank of 13. When dealing with Runs (see description below), these are the ranks to be considered to check for consecutive sequences. For example, 10, J, Q is a run of 3 consecutive cards based on these ranks. However, when summing to Fifteen (see description below), the face cards (J, Q, and K) have values of 10. It's important to remember that the rank of these cards is different for Runs than they are for summing to Fifteen. Examine the provided Card class to see the two different rank getter methods, getRunRank() and getFifteenRank(). Pairs Two cards with the same number/letter label are considered a pair and it is worth 2 points. If you have more than 2 cards with the same number/letter label, each pair would score. For example, suppose you have 2H (2 of Hearts), 2S (2 of Spades), and 2C (2 of Clubs) among your 5 cards. Assignment 2 CS 1027 Computer Science Fundamentals II With these cards, there are three pairs: 2H-2S, 2H-2C, and 2S-2C. Each of those three pairs scores 2 points for a total of 6 points. Runs Three or more cards with consecutive ranks (remember that J, Q, and K have ranks of 11, 12, and 13 respectively for this scoring category) are considered to form a run. Only the longest run will count and will score points equal to the length of the run. For example, if there is 7, 8, 9, and 10, it would score 4 points as a run of 4 cards. The runs of 3 (<7, 8,="" 9=""> and <8, 9,="" 10="">) would not count since the run of 4 is the longest run. If there are multiple runs of the same length, they would all count. For example, if there is 7D, 8H, 9C, 10D, and 10H, there would be two runs of 4 (<7d, 8h,="" 9c,="" 10d=""> and <7d, 8h,="" 9c,="" 10h="">) so both runs would score for a total of 8 points for the two runs. Sometimes there are three or four different runs and they would each score in the same manner. For example, if there is 7D, 8D, 8H, 9S, and 9H, there would be four runs of length 3 (<7d, 8d,="" 9s="">; <7d, 8d,="" 9h="">; <7d, 8h,="" 9s="">; and <7d, 8h,="" 9h="">) so the score from these runs would be 12 points. The above set of cards would yield the following 4 runs: Assignment 2 CS 1027 Computer Science Fundamentals II Each of these runs would score 3 points for a total of 12 points for all the runs. Since the runs are difficult and complex to determine, we are providing you with a private helper method called isRun(Set set) which you are encouraged to use to help in calculating this scoring category. This method will return true if the given set represents a run of 3 or more consecutive ranked cards, and false otherwise. You still have to check if the given run is the longest and only score it if there is no longer run in the sequence. Hint: keep track of the longest run length and then only score the one(s) whose length is the longest. Fifteen Any combination of cards that add up to 15 will score 2 points. For example, 6 and 9 add up to 15 so that would score 2 points. Queen, Ace, and 4 add up to 15 and would also score 2 points. Remember that J, Q, and K are all worth 10 in this scoring category. A card can be used in multiple additions to fifteen. For example, if there is 2D, 2H, 5D, 8D, 8C, there would be multiple add-ups to fifteen (<2d, 5d,="" 8d="">, <2d, 5d,="" 8c="">, <2h, 5d,="" 8d="">, and<2h, 5d,="" 8c="">) so it would score 8 for this category of scoring. Flush If all 4 cards in the hand have the same suit, it is a flush worth 4 points. If the starter also has the same suit as the 4 cards in the hand, then it scores 5 points instead of 4. Assignment 2 CS 1027 Computer Science Fundamentals II (starter) The above set of cards would score 4 points for a flush in the hand. (starter) The above set of cards would score 5 points for a flush in the hand including the starter card. (starter) The above set of cards would score 0 points since the 4 cards in the hand are not all the same suit. His Knobs If there is a Jack within the 4 cards of the hand and its suit matches the suit of the starter card, it is called "His Knobs" and is worth 1 point. (starter) The above set of cards would yield 1 point for "His Knobs" since the starter card's suit is Diamonds and the hand contains a Jack of Diamonds. Assignment 2 CS 1027 Computer Science Fundamentals II (starter) The above set of cards would not yield a point for "His Knobs" since the starter card's suit is Spades and the hand does not contain a Jack of Spades. Important Reminders:  Aces represent (and have a value of) 1 when summing to Fifteen and for Runs  As explained above, Jacks, Queens, and Kings all have values of 10 when summing to Fifteen, but are distinct ranks when it comes to Runs (for example, 8, 9, Jack is not a run even though Jack has a value of 10 in the counting. 10, Jack, Queen is a valid run). o To simplify the ranks of these face cards for runs, we give Jack a value of 11, Queen a value of 12, and King a value of 13. o For summing to Fifteen, these face cards all have a value of 10. Examples of Scoring Totals (starter) Hand: 4H, 2H, KC, 3C Starter: 9D 3pts Run of 3 (2H, 3C, 4H) 2pts Fifteen (2H+3C+KC) 2pts Fifteen (2H+4H+9D) Total points: 7 Assignment 2 CS 1027 Computer Science Fundamentals II (starter) Hand: 10H, JS, QC, QD Starter: 5S 2pts Pair of Queens 3pts Run of 3 (10H, JS, QC) 3pts Run of 3 (10H, JS, QD) 2pts Fifteen (5S+10H) 2pts Fifteen (5S+JS) 2pts Fifteen (5S+QC) 2pts Fifteen (5S+QD) 1pt His Knobs (JS same suit as starter 5S) Total points: 17 (starter) Hand: AD, JC, KC, 4H Starter: 4C 2pts Fifteen (AD+4H+JC) 2pts Fifteen (AD+4C+JC) 2pts Fifteen (AD+4H+KC) 2pts Fifteen (AD+4C+KC) 2pts Pair of Fours 1pt His Knobs (JC same suit as starter 4C) Total points: 11 Assignment 2 CS 1027 Computer Science Fundamentals II Some of the categories of scoring are dependent on multiple combinations of cards, so we will use a Power Set to generate all the different possible combinations of cards so that we can examine each set in the Power Set to compute the total score. A Power Set means a series of sets that covers every possible combinations of element(s) from the original set, including an empty set. For example, from the set {1, 2, 3}, the Power Set would include all of the following sets: {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}, and {}. Note that for any set with n elements, its Power Set will contain 2n sets. In this example, there are 3 elements, so the Power Set contains 23 = 8 sets. Classes to Implement For this assignment, you must implement three (3) Java classes: Set, PowerSet, and Counter. Follow the guidelines for each one below. In these classes, you may implement more private (helper) methods if you want. However, you may not implement more public methods except public static void main(String[] args) for testing purposes (this is allowed and encouraged). You may not add instance variables other than the ones specified in these instructions nor change the variable types or accessibility (i.e. making a variable public when it should be private). Penalties will be applied if you implement additional instance variables or change the variable types or modifiers from what is described here. Set.java This class represents a simple collection that must be implemented with a singly-linked list. This class must work for the generic type T. The class must have the following private variable:  LinearNode setStart (the front of the linked list) The class must have the following public methods:  public Set(): constructor  Initialize setStart to null  public void add(T element)  Create a new node containing the given element and add the new node to the linked list. The order does not really matter for a Set, so you can either add to the end or the start of the linked list for simplicity. Make sure you update the links properly and account for different cases (i.e. adding the first node to an empty list, adding a node to a list with other nodes, etc.)  public int getLength()  Return the number of items in the linked list  public T getElement(int i) Assignment 2
Answered 3 days AfterFeb 24, 2023

Answer To: CS XXXXXXXXXXAsst 2Assignment 2 CS 1027 Computer Science Fundamentals II Due...

Aditi answered on Feb 27 2023
39 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here