Question: 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

 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

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) - Returns the element stored in the ith node of the linked list (NOTE: remember that order does not matter, so this method is not being tested in the autograded tests but it may be very useful for you when implementing the Counter class and you need to extract individual elements from a Set within a loop). - public boolean contains(T element) - Returns true if the given element is found within the linked list; false otherwise - public String toString() - Returns a string containing each of the elements in the Set separated by a space PowerSet.java This class represents the Power Set from a given set. This class must also work with the generic type T. The class must have the following private variable: - Set[] set The class must have the following public methods: - public PowerSet(T] elements): constructor - Generate the Power Set from the given T array of elements - See the hints below (Power Set Generation) for help on how to approach this - Store the series of sets for this Power Set in the instance variable, set. - public int getLength() - Return the number of items in the array (the number of sets in the Power Set) - public Set getSet(int i) - Return the Set stored at index i of the array Power Set Generation Creating a Power Set might sound difficult but there is a recommended approach that simplifies the process. - A Power Set for a set of n elements will contain 2n sets. - To generate each of the 2n sets with the proper combination of elements, take the binary representation of each number from 0 to 2n1. Hint: you can use Integer.toBinaryString (x) to convert an int, x, to its binary representation as a String. - Ensure that all the binary numbers have the same number of digits (they will need to have n digits) using padded zeroes at the front, i.e. 0001. - Loop through each binary number and through each digit (bit) of the binary number. Whenever the digit (bit) is a 1, add the item from the original set at the corresponding index into the proper set for the Power Set (see the Example table below and the resulting sets (below the table) that would be produced from each binary number) Counter.java This class will be used to calculate the number of points from a Cribbage hand. The class must have the following private variables: - PowerSet cardps - Card starter The class must have the following public methods: - public Counter(Card]] hand, Card starter): constructor - Initialize the starter and use the PowerSet constructor to generate the Power Set of the cards from the hand (note that the starter card is already included in the hand array so the Power Set will be based on all 5 cards. - public int countPoints() - Calculate the number of points for the hand that was sent into the constructor. Use the Power Set, cardps, to do the calculations so that all the combinations are checked. Refer to the scoring explanations in the Introduction when implementing this method. - It is recommended that you implement one or more private helper methods to help keep the code more organized and clean. For example, you may want private helper methods for each of the scoring categories, i.e. one for checking if a given Set sums to 15, another one to check if the given Set forms a run of 3 or more consecutive cards, etc

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!