Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Instructions: Setting up the project ( 2 points ) Create a new Java project called Module02Test . Add a package called m02 and inside this

Instructions:

Setting up the project ( 2 points )

Create a new Java project called Module02Test. Add a package called m02 and inside this package, a class Module02 that includes a main method. In addition, add the classes Card, UnoCard, and PokerCard. You may want to create enums for this assignment. Feel free to do so!

Style | Doc Comments (5 points)

Follow style guidelines and best practices as specified in the Style Guide. Pay special attention to the expectations for Doc Comments.

Requirements: (42 points)

Implement the classes as specified in the following UML Class Diagram and the additional instructions below. No class members should be added, removed, or changed. Important: Avoid code duplication.

Class Card: // 12 out of 42 points

Constructor:

Assigns v to value;

Override the method compareTo:

Returns the expected -1 (Less Than), 0 (Equal To), or 1 (Greater Than) result based the toString() results. (You'll likely need to explicitly call toString). Tip: String uses compareTo as well.

Method equals:

Returns a boolean value bases on if the class is the same and if the value is the same. (You should be able to just compare the toString values) Tip: Strings have an equals method too...

Method toString:

It should return a string that includes the type of the card (UnoCard or PokerCard) and the value (e.g. PokerCard: 1) Note: The default implementation from Eclipse does NOT fulfill the requirements

Method play:if the topCard is equal(s) to this

prints out "I just played a _____________ " where the blank is the toString result.

if the topCard is not equal(s) to thiscompare the values of the two Cards

For the higher value print "AND THE WINNER IS.... ________ " where the blank is the toString of the higher valued Card.

If the values are equal then print "IT'S A TIE!!" or something.

Method getValue:

Just a getter. return value.

Class UnoCard: // 11 out of 42 points

Constructor:

has Card assign value and store c in color (valid color options are: Blue, Yellow, Red, Green

Method play: You have to determine if the current card is playable based on topCard (parameter)if topCard is not an UnoCard then

call super class's play and pass topCard

topCard is an UnoCard AND (this.color must equal topCard.color OR this.value must equal topCard.value)

If it works print "Playing ________" where blank is toString.

Otherwise, print "Drawing 1"

Method getColor:

Just a getter, return color.

Override the method toString:

Should do the same as Card but add the color at the end (e.g.: UnoCard: 1 Red). Tip: don't rewrite the code for Card's toString.

Class PokerCard: // 11 out of 42 points

Constructor:

has Card assign value and store s in suit

Suits should be one of these: (\u2660), (\u2665), (\u2663), (\u2666). You should be able to copy-paste the symbols and not use the char values. Maybe use some final variables...

Method getSuit:

Just a getter. return suit.

Override the method toString:

Should do the same as Card but add the suit to the end (e.g. PokerCard: 1) Tip: don't rewrite the code for Card's toString.

Class Module02: // 8 out of 42 points

Class Module02 is the test client and it includes the main method. Within the main method do the following:

Create an ArrayList of type Card and initialize it with 10 random UnoCard and 10 random PokerCard:Create a loop that will:

Randomly determine the value of the card ( 1 - 12 just to be consistent )

Randomly determine the color (for UnoCards)

Randomly determine the suit (for PokerCards)

Create new instance and assign to the ArrayList

Using Collections.shuffle, shuffle your arraylist... do this a few times. Just to be thorough

Print the ArrayList

Using Collections.sort, sort the ArrayList.

Loop through all the elements in the list. For each element do the following:

NOTE: I had to troubleshoot this a bit when I did it just because I didn't get all 20 to show up. You may want to have it print the current slot number just to test it. I don't want to see current number in the final output.

play the card

If it is the first Card (no prior Card to use) just pass the current card as the topCard.

If it's not the first Card then pass the prior card in the ArrayList

Note:

If we were to make an entire arraylist of PokerCard such that we had a full deck of 52 cards represented and then we shuffled a few (read: lots) times, then split that ArrayList into 2 ArrayLists... then took the slot 0 ( remove(0) ) PokerCard from both ArrayLists and compared the values of the two cards to determine which card was higher... then added both of those cards and gave them to the ArrayList with the higher card value... That sounds like a game I know...

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

JAR File (1 point)

Create a JAR file that includes all source code files of the project Module02Test. Whether the JAR file is runnable or not is irrelevant.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions