Practice/Amazon/Design a Card Game
Object Oriented DesignMust
Design an object-oriented system to evaluate and compare poker hands. Your implementation should represent cards, hands, and game logic through well-structured classes that can determine which of two poker hands wins according to standard poker rankings.
Each card is represented as a two-character string: the first character is the rank (2-9, T for 10, J for Jack, Q for Queen, K for King, A for Ace), and the second character is the suit (H for Hearts, D for Diamonds, S for Spades, C for Clubs).
Card Class: Represent individual playing cards with rank and suit
Hand Class: Represent a collection of 5 cards and evaluate the hand's poker ranking
PokerGame Class: Compare two hands and determine the winner
Hand Rankings (from highest to lowest):
When hands have the same ranking, compare by the highest relevant cards
Implement a determineWinner function that returns "Player 1", "Player 2", or "Tie"
Example 1:
Input: Player 1: ["2H", "4D", "6S", "8C", "9H"] Player 2: ["3H", "3D", "7S", "9C", "JH"] Output: "Player 2" Explanation: Player 2 has a pair of 3s, which beats Player 1's high card hand (highest card 9).
Example 2:
Input: Player 1: ["KH", "KD", "2S", "5C", "7H"] Player 2: ["2H", "5H", "7H", "9H", "JH"] Output: "Player 2" Explanation: Player 2 has a flush (all hearts), which ranks higher than Player 1's pair of Kings.
Example 3:
Input: Player 1: ["TH", "JH", "QH", "KH", "AH"] Player 2: ["9S", "9D", "9C", "9H", "KS"] Output: "Player 1" Explanation: Player 1 has a Royal Flush, the highest possible hand in poker.
Example 4:
Input: Player 1: ["5H", "5D", "2S", "8C", "9H"] Player 2: ["QH", "QD", "3S", "6C", "7H"] Output: "Player 2" Explanation: Both players have a pair, but Queens rank higher than 5s.