Question
how do I get this to compile? Currently there is an issue on class Module02 outputting random colors for the uno cards and random suit
how do I get this to compile? Currently there is an issue on class Module02 outputting random colors for the uno cards and random suit for the poker card
the expected output should be
Sample Output (Due to Randomness your output will not be the same though the format will be the same):
[UnoCard: 7 YELLOW, PokerCard: 1, PokerCard: 11, PokerCard: 1, PokerCard: 3, UnoCard: 9 RED, UnoCard: 6 BLUE, UnoCard: 6 BLUE, UnoCard: 2 GREEN, PokerCard: 1, UnoCard: 12 YELLOW, PokerCard: 10, UnoCard: 5 BLUE, PokerCard: 6, UnoCard: 8 RED, PokerCard: 3, UnoCard: 2 GREEN, UnoCard: 9 RED, PokerCard: 12, PokerCard: 5] I just played PokerCard: 10 I just played PokerCard: 11 AND THE WINNER IS....PokerCard: 12 AND THE WINNER IS....PokerCard: 12 IT'S A TIE!!! I just played PokerCard: 1 AND THE WINNER IS....PokerCard: 3 IT'S A TIE!!! AND THE WINNER IS....PokerCard: 5 AND THE WINNER IS....PokerCard: 6 AND THE WINNER IS....UnoCard: 12 YELLOW Drawing 1 Playing UnoCard: 2 GREEN Drawing 1 Playing UnoCard: 6 BLUE Playing UnoCard: 6 BLUE Drawing 1 Drawing 1 Playing UnoCard: 9 RED Playing UnoCard: 9 RED
the code I have so far is as follows
please see what I am missing
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class Module02 { public static void main(String[] args) { ArrayList
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public abstract class Card implements Comparable
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class PokerCard extends Card {
public enum Suit { SPADES("\u2660"), HEARTS("\u2665"), CLUBS("\u2663"), DIAMONDS("\u2666"); private final String symbol;
Suit(String s) { symbol = s; }
@Override public String toString() { return symbol; } }
private Suit suit;
public PokerCard(int v, Suit s) { super(v); suit = s; }
public Suit getSuit() { return suit; }
@Override public String toString() { return "PokerCard: " + super.getValue() + suit.toString(); } }
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class UnoCard extends Card { private String color; public UnoCard(int value, String color) { super(value); this.color = color; } @Override public void play(Card topCard) { if (!(topCard instanceof UnoCard)) { super.play(topCard); } else { UnoCard topUnoCard = (UnoCard) topCard; if (this.color.equals(topUnoCard.color) || this.value == topUnoCard.value) { System.out.println("Playing " + this.toString()); } else { System.out.println("Drawing 1"); } } } public String getColor() { return color; } @Override public String toString() { return super.toString() + " " + color; } }
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