Question
JAVA PROGRAM STRICTLY FOLLOW THIS TEMPLATE import java.util.LinkedList; import java.util.Collections; import java.util.Iterator; /** * * * * * */ public class Deck { private static
JAVA PROGRAM
STRICTLY FOLLOW THIS TEMPLATE
import java.util.LinkedList; import java.util.Collections; import java.util.Iterator; /** * * * * * */ public class Deck { private static final int NUM = 3; // Number of cards in Deck private Card[] cards; public Deck() { cards = new Card[NUM]; cards[0] = new RelativeMovementCard("Go back 3 spaces", -3); cards[1] = new PayBankCard("Pay poor tax $15", 15); cards[2] = new PayBankCard("Pay school tax of $150", 150); } public void save() { for (int i = 0; i Write a class Deck. This class should declare one instance variable private Card() cards; // chance or community chest cards In the constructor of Deck construct the cards array and add RelativeMovementcard objects and PayBankcard objects to this array. You can assume that there are only 3 cards in the deck and construct these objects as follows new RelativeMovementCard "Go back 3 spaces", -3) new PayBankCard ("Pay poor tax of $15", 15) Add two methods: public void pickcard() This method should remove the first card from the cards array, call the execute method of the Card object and add the card back to the end of the array. public void save () This method should traverse the cards array using an index and call the save method of each card object . Write a small test driver (main) which constructs a Deck object and then calls the pickCard method twice
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