I have this java program assigned for Data Structures using Java and I have the
ID: 3887416 • Letter: I
Question
I have this java program assigned for Data Structures using Java and I have the card class and deck class completed and I’m having trouble with the stack and queue class for it. Any help would be appreciated! program2-2 [Compatibility Mode] References Mailings Review View 2 Caption Heading 1 Heading 2 Data Structures CSC 222 Fall 2017 Programming Assignment #2-50 Points 3 Due by 11:59PM, Wednesday, September 20 So, we're going to be creating a card game... Are you excited yet? You'll be programming a modified version of poker! The rules are simple: the human player places a bet, and then each player (human and computer) is dealt 5 cards and the one with the higher total wins- simple, huh? If the human wins, the computer pays double (Le. you get twice your bet back) and if the computer wins, the bet is lost The game starts by shuffing 2 decks of cards and putting them into a hopper. Then, the following steps occur until the player wants to quit or runs out of money: 1- player places a bet (less than or equal to his/her wallet), 2-each player is dealt 5 cards, and 3-the winner is determined. If there is a ie, the player keeps the bet. When the hopper is empty, the game is over Details: Comments The banner for your program (comment at the top) should include Name, Class Semester, Program number, and program description. The remainder should follow the WJU Computer Science standard. Execution: Your program will first display your welcome message, which should include your name and a brief description of the program (with anyappropriate instructions). Next, it will shuffle and then push 2 decks (array-based decks are fine) of cards into the hopper, which is a stack. Then the user places a bet. Next 5 cards are popped to the users "hand" and 5 cards are popped into the computer's 'hand (both of the "hands" are queues). Then the totals are calculated (by dequeueing from each and and adding up the points) and the winner is determined. Last, the user's wallet is updated. This continues unti the user runs out of money or wants to quit or the hopper is emptied (note that you shouldn't attempt to start a game if there are not enough cards in the hopperl). Implementation You must use an ArrayList-based stack and an ArrayList-based queue. And I would expect to see at least five classes: Main, Stack, Queue, Deck, and Card. Heip Documentation: Include a statement of any outside help received in your main comment block. Submittat: Use the Assignment feature of BlackBoard to submit your program. As always, extra effort will eam extra credit, but be SURE you get the basics down first FocusExplanation / Answer
Class Stack
/* here is the class stack .i have taken two decks as input in constructor and created a single arraylist .then we can pop a arraylist of cards with size of 5 by calling pop method or if hopper has less than 5 cards then it will give null .stack means "last in first out" ,so we take the last element of the arraylist created in the stack */
import java.util.ArrayList;
class stack
{
private Deck A;
private Deck B;
private ArrayList<cards> hopper;
public stack(Deck a,Deck b)
{
this.A=a;
this.B=b;
}
public void init()
{
hopper=new ArrayList<Cards>();
initialize();
}
public Boolean isEmpty()
{
if(this.hopper==Null)
{
return TRUE;
}
else
return FALSE;
}
private void initialize()
{
while(!A.isEmpty())
{
hopper.add(A.dealOne());
}
while(!B.isEmpty())
{
hopper.add(B.dealOne());
}
}
public ArrayList<Cards> pop()
{
if(hopper.size()>=5)
{
ArrayList<Cards> at=new ArrayList<Cards>();
for(int i=0;i<5;i++)
{at.add(hopper.get(hopper.size()-1));
hopper.remove(hopper.size()-1)} //removes the last element
return at;
}
else
{
return NULL;
}
}
}
Class queue
/* here is the class queue in this we will pass the return arraylist of stack class method pop .then we call pop method of class queue to get each card in queue fashion that is first in first out*/
import java.util.ArrayList;
class queue
{
private ArrayList<Cards> AR;
queue(ArrayList<cards> c)
{
this.AR=c;
}
public Cards pop()
{
if(AR!=NULL and !AR.isEmpty())
{
Cards t=AR.remove(0);//gives the first element else return null
}
else
{
return NULL;
}
}
}
}