Question

2. Activity Directions: Create a UML diagram and then write the code for the object classes needed for your UNO game. You will need a minimum of three classes: a. A Card class (models an individual UN...

2. Activity Directions: Create a UML diagram and then write the code for the object classes
needed for your UNO game. You will need a minimum of three classes:
a. A Card class (models an individual UNO card)
b. A Hand class (models a player's hand)
c. A Deck class (models the entire UNO deck)
You may add other classes as you see fit.
Test your program by writing a console application (a driver program) that creates a deck
of UNO cards, deals the cards to two or more players, and displays the contents of each
player's hand.

I am using Java 8 and the ide eclipse for testing

1 0
Add a comment Improve this question Transcribed image text
✔ Recommended Answer
Answer #1

package pavan.uno;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.Iterator;

import java.util.Map;

import java.util.Random;

public class PopulatingDeck {

private static Map<Long,String> map;

private static Map<String,Integer> mapDeck;

private static ArrayList <String> finalDeck;

private static boolean cardShow= false;

private static String checkCardKey;

private static boolean MapContainsValueFlag= false;

private static String cardValueRecieved;

    public PopulatingDeck(){

        map=new HashMap<Long,String>();

        finalDeck=new ArrayList<String>();

        mapDeck=new HashMap<String,Integer>();

        map.put(new Long(0), "blue");

        map.put(new Long(1), "green");

        map.put(new Long(2), "yellow");

        map.put(new Long(3), "red");

        generateDeck();

    }

     

   

    public static void main(String[] args) {

        // TODO Aut#o-generated method stub#

        System.out.println("hiiiiiiiii");

        PopulatingDeck generatingDeck=new PopulatingDeck();

      for(int i=0;i<finalDeck.size();i++){

          System.out.println(finalDeck.get(i)+" \n");

      }

          

         

    }

     

    private static String randomColorGeneration(){

        long temp=Math.round(Math.random()*3);

            if(map.containsKey(temp)){

                return map.get(temp);

            }

            else{

                return null;

            }

}

    public static void generateDeck(){

        for(int i=0;finalDeck.size()<108;i++){

            cardShow=cardDisplayCheck();

            if (cardShow)

                finalDeck.add(checkCardKey);

        }           

          }

     

    public static String randCardNumber() {

         String returnString;

        Random rand = new Random();

         int randomNum = rand.nextInt(15);

        if(randomNum>=10 && randomNum<15){

            switch(randomNum){

            case 10: return "+2";

            case 11: return "Skip";

            case 12: return "Reverse";

            case 13: return "WildCard-Farbe";

            case 14: return "WildCard- +4";package pavan.uno;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.Iterator;

import java.util.Map;

import java.util.Random;

public class PopulatingDeck {

private static Map<Long,String> map;

private static Map<String,Integer> mapDeck;

private static ArrayList <String> finalDeck;

private static boolean cardShow= false;

private static String checkCardKey;

private static boolean MapContainsValueFlag= false;

private static String cardValueRecieved;

    public PopulatingDeck(){

        map=new HashMap<Long,String>();

        finalDeck=new ArrayList<String>();

        mapDeck=new HashMap<String,Integer>();

        map.put(new Long(0), "blue");

        map.put(new Long(1), "green");

        map.put(new Long(2), "yellow");

        map.put(new Long(3), "red");

        generateDeck();

    }

     

   

    public static void main(String[] args) {

        // TODO Aut#o-generated method stub#

        System.out.println("hiiiiiiiii");

        PopulatingDeck generatingDeck=new PopulatingDeck();

      for(int i=0;i<finalDeck.size();i++){

          System.out.println(finalDeck.get(i)+" \n");

      }

    }

     

    private static String randomColorGeneration(){

        long temp=Math.round(Math.random()*3);

            if(map.containsKey(temp)){

                return map.get(temp);

            }

            else{

                return null;

            }

}

    public static void generateDeck(){

        for(int i=0;finalDeck.size()<108;i++){

            cardShow=cardDisplayCheck();

            if (cardShow)

                finalDeck.add(checkCardKey);

        }           

          }

     

    public static String randCardNumber() {

         String returnString;

        Random rand = new Random();

         int randomNum = rand.nextInt(15);

        if(randomNum>=10 && randomNum<15){

            switch(randomNum){

            case 10: return "+2";

            case 11: return "Skip";

            case 12: return "Reverse";

            case 13: return "WildCard-Farbe";

            case 14: return "WildCard- +4";

            }

        }

            else{

            returnString=String.valueOf(randomNum);

        return returnString;

        }

        return null;

        }

     

    public static boolean cardDisplayCheck(){

        String localCardNumberDisplay=randCardNumber();

        if(!localCardNumberDisplay.startsWith("W")){

         checkCardKey=localCardNumberDisplay+" - " +randomColorGeneration();

        }

        else{

             checkCardKey=localCardNumberDisplay;

        }

        int cardCounter=0;

        if(!MapContainsValueFlag||!mapDeck.containsKey(checkCardKey)){

            mapDeck.put(checkCardKey, ++cardCounter);

            MapContainsValueFlag=true;

            return true;

    }

        if(checkCardKey.startsWith("0") && mapDeck.containsKey(checkCardKey)){

                return false;

             

        }

        if(checkCardKey.startsWith("W") && mapDeck.containsKey(checkCardKey)&& mapDeck.get(checkCardKey)<4){

            mapDeck.put(checkCardKey, mapDeck.get(checkCardKey)+1);

            return true;

         

    }

         

        if(mapDeck.containsKey(checkCardKey)){

               if(mapDeck.get(checkCardKey)<2){

                   mapDeck.put(checkCardKey, mapDeck.get(checkCardKey)+1);

                   return true;

               }

        }

        return false;

    }      

}

             

            }

        }

            else{

            returnString=String.valueOf(randomNum);

        return returnString;

        }

        return null;

        }

     

    public static boolean cardDisplayCheck(){

        String localCardNumberDisplay=randCardNumber();

        if(!localCardNumberDisplay.startsWith("W")){

         checkCardKey=localCardNumberDisplay+" - " +randomColorGeneration();

        }

        else{

             checkCardKey=localCardNumberDisplay;

        }

        int cardCounter=0;

        if(!MapContainsValueFlag||!mapDeck.containsKey(checkCardKey)){

            mapDeck.put(checkCardKey, ++cardCounter);

            MapContainsValueFlag=true;

            return true;

    }

        if(checkCardKey.startsWith("0") && mapDeck.containsKey(checkCardKey)){

                return false;

             

        }

        if(checkCardKey.startsWith("W") && mapDeck.containsKey(checkCardKey)&& mapDeck.get(checkCardKey)<4){

            mapDeck.put(checkCardKey, mapDeck.get(checkCardKey)+1);

            return true;       

    }

         

        if(mapDeck.containsKey(checkCardKey)){

               if(mapDeck.get(checkCardKey)<2){

                   mapDeck.put(checkCardKey, mapDeck.get(checkCardKey)+1);

                   return true;

               }

        }

        return false;

    }  

}

Theme Enumeration Suit Deck Card suit. Suit shuffle() 曰Clubs 1.. kind: Kind Diamonds Hearts Spades getSuit(): Suit getKind():

Add a comment
Know the answer?
Add Answer to:
2. Activity Directions: Create a UML diagram and then write the code for the object classes needed for your UNO game. You will need a minimum of three classes: a. A Card class (models an individual UN...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • 2 A Game of UNO You are to develop an interactive game of UNO between a...

    2 A Game of UNO You are to develop an interactive game of UNO between a number of players. The gameplay for UNO is described at https://www.unorules.com/. Your program should operate as follows. 2.1 Setup 1. UNO cards are represented as variables of the following type: typedef struct card_s { char suit[7]; int value; char action[15]; struct card_s *pt; } card; You are allowed to add attributes to this definition, but not to remove any. You can represent colors by...

  • Create a simplified Blackjack game using the Deck and Card classes (download the attached files to...

    Create a simplified Blackjack game using the Deck and Card classes (download the attached files to start).  There is also a "TestCard" class that creates a Deck and runs some simple code. You may choose to use this file to help you get started with your game program. 1) Deal 2 cards to the "player" and 2 cards to the "dealer".  Print both the player's cards, print one of the dealer's cards. Print the total value of the player's hand. 2) Ask...

  • CARD GAME (LINKING AND SORTING) DATA STRUCTURES TOPIC(S) Topic Primary Linked lists Sorting Searching Iterators As...

    CARD GAME (LINKING AND SORTING) DATA STRUCTURES TOPIC(S) Topic Primary Linked lists Sorting Searching Iterators As needed Recursion OBJECTIVES Understand linked lists and sorting concepts and the syntax specific to implementing those concepts in Java. PROJECT The final objective of this project is to create a multi-player card game, but you will create your classes in the order given, as specified. (Analogy: you must have a solid foundation before you can build a house). In order to allow creative freedom,...

  • For this project your card class must include an Image of the card. Here is a...

    For this project your card class must include an Image of the card. Here is a zip filecontaining 52 images you can use for your cards. Please note that the name for each card can be created by the concatenation of the first character of the suit, the value of the card, and the ".png" suffix. When you construct a card, you should have it load its image. Alternatives exist regarding how to draw() the card. One way to do...

  • While using JAVA , solve this. There are three basic classes we'll need this week: Card:...

    While using JAVA , solve this. There are three basic classes we'll need this week: Card: A class like the one presented in the modules, but with a few changes. Hand: A class that represents the cards held by a single player. Deck: A class that represents the source of the cards for dealing and, as the game progresses, the place from which players can receive new cards (say, as they pick cards "from the deck" or when future hands...

  • Using C++ Create a Blackjack program with the following features: Single player game against the dealer....

    Using C++ Create a Blackjack program with the following features: Single player game against the dealer. Numbered cards count as the number they represent (example: 2 of any suit counts as 2) except the Aces which can count as either 1 or 11, at the discretion of the player holding the card. Face cards count as 10. Player starts with $500. Player places bet before being dealt a card in a new game. New game: Deal 2 cards to each...

  • Here’s your task: You’re going to create exactly two classes. One class will act as the...

    Here’s your task: You’re going to create exactly two classes. One class will act as the functional server. The main method of this server will setup the connection on a localhost, find the two clients, let them know which one is Player 1 and which one is Player 2 (depending on the order they connect), and then manage the game as it’s being played. This is important: For each player’s turn they should start by displaying their current score to...

  • This is my code for my game called Reversi, I need to you to make the...

    This is my code for my game called Reversi, I need to you to make the Tester program that will run and complete the game. Below is my code, please add comments and Javadoc. Thank you. public class Cell { // Displays 'B' for the black disk player. public static final char BLACK = 'B'; // Displays 'W' for the white disk player. public static final char WHITE = 'W'; // Displays '*' for the possible moves available. public static...

  • Using Java You are helping a corporation create a new system for keeping track of casinos...

    Using Java You are helping a corporation create a new system for keeping track of casinos and customers. The system will be able to record and modify customer and casino information. It will also be able to simulate games in the casino. Customer-specific requirements You can create new customers All new customers have a new customerID assigned to them, starting with 1 for the first, 2 for the second, 3 for the third, ect. New customers have names and monetary...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT