Question
6. Write a function called SortHandOfCards Input Parameters: a list/vector/array of Card objects For bonus, add a boolean value sortDescending - that says whether or
6. Write a function called SortHandOfCards Input Parameters: a list/vector/array of Card objects For bonus, add a boolean value sortDescending - that says whether or not the sort is ascending or descending Return Parameter: a list/vector/array of Card objects that are sorted Each card object has a function called get_suit() that returns the suit of the card as a string: Hearts, Spades, Clubs, Diamonds. Cards also have a function called get_value() that returns a character representing their value - A,2,3,4,5,6,7,8,9,0,J,Q,K (note that the 10 is represented as a 0 since it can only be one character) The cards are ordered by value then by suit, where Aces (A) have the lowest point value, followed by 2, and Kings (K) have the highest point value. For suits, assume that Hearts < Diamonds < Clubs < Spades Feel free to write helper functions or other functions associated with the Card object to help accomplish the task. The default for the sort is ascending unless sortDescending is true. An example of a hand sorted in ascending order is Ace of hearts, Aces of Spades, 3 of clubs, 7 of hearts
below is some quick psuedo code i wrote for it feel free to change anything about it
public class Card implements Comparable
private SUIT cardSuit; private int cardRank;
public enum SUIT {SPADE, CLUB, HEART, DIAMOND};
public Card(int cardRank, SUIT cardSuit) { this.cardSuit = cardSuit; this.cardRank = cardRank; }
/** * Generates a random card */ public Card(){ this((int) (Math.random() * 9) , SUIT.values()[(int) (Math.random() * SUIT.values().length)]); }
public String getSuit() { return cardSuit.toString(); }
public int getRank() { return cardRank; }
@Override public int compareTo(Card2 o) { if (this.cardRank == o.cardRank) { return this.cardSuit.compareTo(o.cardSuit);
} else { return o.cardRank - this.cardRank; } }
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started