Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

//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

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

Recommended Textbook for

Filing And Computer Database Projects

Authors: Jeffrey Stewart

2nd Edition

007822781X, 9780078227813

More Books

Students also viewed these Databases questions

Question

Complexity of linear search is O ( n ) . Your answer: True False

Answered: 1 week ago