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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

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

Post 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 49 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 49 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 } } {
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply