Page 1 of 1

Task 3: Put on Your Poker Face Create a class, Card, that encapsulates the idea of single Poker card with a suit (Diamon

Posted: Thu May 05, 2022 12:40 pm
by answerhappygod
Task 3 Put On Your Poker Face Create A Class Card That Encapsulates The Idea Of Single Poker Card With A Suit Diamon 1
Task 3 Put On Your Poker Face Create A Class Card That Encapsulates The Idea Of Single Poker Card With A Suit Diamon 1 (49.92 KiB) Viewed 51 times
Task 3 Put On Your Poker Face Create A Class Card That Encapsulates The Idea Of Single Poker Card With A Suit Diamon 2
Task 3 Put On Your Poker Face Create A Class Card That Encapsulates The Idea Of Single Poker Card With A Suit Diamon 2 (43.81 KiB) Viewed 51 times
Task 3: Put on Your Poker Face Create a class, Card, that encapsulates the idea of single Poker card with a suit (Diamonds, Clubs, Hearts, or Spades) and a rank (2-10, Jack, Queen, King, or Ace). We will represent the suit as an integer (0-3), where 0 ⇒ Diamonds, 1⇒ Clubs, 2 ⇒ Hearts, and 3 ⇒ Spades. The rank will be represented as an integer as well (0-12), where 0 ⇒ rank 2, 1 ⇒ rank 3, ... 9 → Jack, 10 → Queen, .... Requirements FIELDS rank: private int rank suit: private int suit Card(): public Card() Card(): public Card (int, int) METHODS compare(): public static int compare(Card, Card) equals(): public boolean equals(java.lang.Object) getRank(): public int getRank() getSuit(): public int getSuit() setRank(): public void setRank(int) setSuit(): public void setSuit(int) to String(): public java.lang. String to String() CONSTRUCTORS Card
CardClient.java public class CardClient { public static void main(String [] args) { // make all the cards and print them for (int suit = 0; suit < 4; suit++) { for (int rank = 0; rank < 13; rank++) Card c = new Card(suit, rank); System.out.println(c); } } // make some invalid cards and print them Card invalid = new Card(4, 0); invalid = new Card(0, 13); // compare some cards (in style of War) Card c1 = new Card(0, 0); // 2 of diamonds Card c2= new Card (3, 0); // 2 of spades System.out.println("Comparing " + c1 + to " + c2 + ": " + Card.compare(c1, c2)); c1 = new Card(0, 0); // 2 of diamonds c2= new Card (0, 2); // 4 of diamonds System.out.println("Comparing " + c1 to " + c2 + ": " + Card.compare(c1, c2)); " c1 = new Card (1, 10); // Queen of clubs c2 = new Card(0, 3); // 5 of diamonds System.out.println("Comparing " + c1 + + c2 + ": " + Card.compare(c1, c2)); to } } {