Question: //Activity 5 import cards.*; import hands.*; public class Activity5 { public static void main(String[] args) { Deck d = new Deck(52); HandOfCards hand = new

 //Activity 5 import cards.*; import hands.*; public class Activity5 { public

//Activity 5 import cards.*;
import hands.*;
public class Activity5 {
public static void main(String[] args) {
Deck d = new Deck(52);
HandOfCards hand = new HandOfTwo();
hand.addCard(d.dealOne());
hand.addCard(d.dealOne());
System.out.println("Hand :");
hand.printHand();
}
package hands;
import cards.PlayingCard;
// HandOfTwo is a class implementing a hand of 2 cards using 2 variables
public class HandOfTwo implements HandOfCards {
PlayingCard card1;
PlayingCard card2;
public void HandOf2() {
card1 = null;
card2 = null;
}
public void addCard(PlayingCard c) {
if (card1 == null)
card1 = c;
else if (card2 == null)
card2 = c;
// else hand is full, do nothing
}
public void printHand() {
if (card1 != null)
System.out.println("Card 1: " + card1);
if (card2 != null)
System.out.println("Card 2: " + card2);
}
}

Recall that the source code has two implementations of a HandOfCards. Add a new hand of cards class called LinkedListHand that uses the linked list class we made in class (not the implementation from the book or the Java API) as the underlying data structure. Your new class should be part of the hands package. In your driver, create a new hand of cards using the linked list hand of cards class and display its contents

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!