Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

// Program deals two Poker \"hands\" import javax.swing.*; import java.awt.*; im

ID: 3821779 • Letter: #

Question

// Program deals two Poker "hands"

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class Poker2 extends Jframe

{

private Card deck[],hand1[],hand2[];

private int currentCard;

private Jbutton dealButton,shuffleButton;

private JTextField handField1,handField2;

private JTextArea displayCard1,displayCard2;

private JLabel handLabel1,handlabel2,status;

private String faces[],suits[],output;

private int numbers1[],numbers2[];

private int highValue1,highValue2,group1,group2;

private boolean straightHand1,straightHand2,pair1,pair2;

private final int>

private final int TWOPAIR = 4;

private final int THREEKIND = 6;

private final int STRAIGHT = 8;

private final int FULLHOUSE = 10;

private final int FLUSH = 12;

private final int FOURKIND = 14;

private final int STRAIGHTFLUSH = 16;

public POKER2 ();

}

super("Card Dealing Program");

String f[] = {"Ace","Deuce","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King"};

String s[] = {"Hearts","Diamonds","Clubs","Spades"};

faces = f;

suits = s;

numbers1 = new int[ 13 ] ;

numbers2 = new int[ 13 ];

hand1 = new Card [ 5 ];

hand2 = new Card [ 5 ];

deck = new Card [ 52 ];

currentCard = -1;

for (int i = 0;i<deck.lenghth;i++)

deck[i] = new Card (faces[i%13],suits[i/13]);

Container container = getContentPane();

container.setLayout(new FlowLayout());

dealButton = newJButton("Deal hand");

dealButton.addActionListner(

new ActionListner(){ // anonymous inner class

//deal hands

public void actionPerformed (ActionEvent event)

{

handfield1.setText("");

handfield2.setText("");

displayCard1.setText("");

displayCard2.setText("");

output = "";

group1 = 0;

group2 = 0;

highValue1 = 0;

highValue2 = 0;

// deal hands

for(int n = 0;n< hand1.length;n++) {

Card dealt1 = dealCard();

Card dealt2 = dealCard();

of(dealt1 != null&& dealt2 ! = null) {

hand1[n] = dealt1;

hand2[n] = dealt2;

displayCard1.setText(

displayCard1.getText()+

hand1[n].toString()+" ");

displayCard2.setText(

displayCard2.getText()+

hand2[n].toString()+" ");

}

//not enough cards to deal

else if(dealt1 ==null || dealt2 == null) {

status.setText("NOT ENOUGH CARDS.SHUFFLE DECK.");

return;

}

}

totalHand(); // calculate contents of hands

pair();

threeOfAKind();

fourOfAKind();

straight();

flush();

When I run this program,I get this error.-

Deckofcard.java:94: error: class, interface, or enum expected

straight();

^

Deckofcard.java:95: error: class, interface, or enum expected

flush();

^

44 errors

----jGRASP wedge2: exit code for process is 1.

----jGRASP: operation complete.

----jGRASP exec: javac -g Deckofcard.java

---- at: Apr 20, 2017 2:08:24 AM

----jGRASP wedge: pid for wedge is 1164.

----jGRASP wedge2: pid for wedge2 is 8560.

----jGRASP wedge2: CLASSPATH is ";.;;;C:Program Files (x86)jGRASPextensionsclasses".

----jGRASP wedge2: working directory is [C:UsersBaniDocuments] platform id is 2.

----jGRASP wedge2: actual command sent ["C:Program FilesJavajdk1.8.0_121injavac.exe" -g Deckofcard.java].

----jGRASP wedge2: pid for process is 3252.

Deckofcard.java:27: error: invalid method declaration; return type required

public POKER2 ();

^

Deckofcard.java:29: error: class, interface, or enum expected

super("Card Dealing Program");

^

Deckofcard.java:31: error: class, interface, or enum expected

String f[] = {"Ace","Deuce","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King"};

^

Deckofcard.java:32: error: class, interface, or enum expected

String s[] = {"Hearts","Diamonds","Clubs","Spades"};

^

Deckofcard.java:34: error: class, interface, or enum expected

faces = f;

^

Deckofcard.java:35: error: class, interface, or enum expected

suits = s;

^

Deckofcard.java:36: error: class, interface, or enum expected

numbers1 = new int[ 13 ] ;

^

Deckofcard.java:37: error: class, interface, or enum expected

numbers2 = new int[ 13 ];

^

Deckofcard.java:38: error: class, interface, or enum expected

hand1 = new Card [ 5 ];

^

Deckofcard.java:39: error: class, interface, or enum expected

hand2 = new Card [ 5 ];

^

Deckofcard.java:40: error: class, interface, or enum expected

deck = new Card [ 52 ];

^

Deckofcard.java:41: error: class, interface, or enum expected

currentCard = -1;

^

Deckofcard.java:43: error: class, interface, or enum expected

for (int i = 0;i<deck.lenghth;i++)

^

Deckofcard.java:43: error: class, interface, or enum expected

for (int i = 0;i<deck.lenghth;i++)

^

Deckofcard.java:43: error: class, interface, or enum expected

for (int i = 0;i<deck.lenghth;i++)

^

Deckofcard.java:46: error: class, interface, or enum expected

Container container = getContentPane();

^

Deckofcard.java:47: error: class, interface, or enum expected

container.setLayout(new FlowLayout());

^

Deckofcard.java:49: error: class, interface, or enum expected

Please fix these errors and update it

Explanation / Answer

complete code for an execution:-)

public class CardPoker
{
private short rank, suit;

private static String[] suits = { "hearts", "spades", "diamonds", "clubs" };
private static String[] ranks = { "Ace", "2", "3", "4", "5", "6", "7",
"8", "9", "10", "Jack", "Queen", "King" };

public static String rankAsString( int __rank )
{
return ranks[__rank];
}

Card(short suit, short rank)
{
this.rank=rank;
this.suit=suit;
}

public @Override String toString()
{
return ranks[rank] + " of " + suits[suit];
}

public short getRank() {
return rank;
}

public short getSuit() {
return suit;
}
}

public class DeckPoker
{
private ArrayList<Card> cards;

DeckPoker()
{
cards = new ArrayList<Card>();
int index_1, index_2;
Random generator = new Random();
Card temp;

for (short a=0; a<=3; a++)
{
for (short b=0; b<=12; b++)
{
cards.add( new Card(a,b) );
}
}

int size = cards.size() -1;

for (short i=0; i<100; i++)
{
index_1 = generator.nextInt( size );
index_2 = generator.nextInt( size );

temp = (Card) cards.get( index_2 );
cards.set( index_2 , cards.get( index_1 ) );
cards.set( index_1, temp );
}
}

public Card drawFromDeck()
{   
return cards.remove( cards.size()-1 );
}

public int getTotalCards()
{
return cards.size();
//we could use this method when making
//a complete poker game to see if we needed a new deck
}
}

public class HandPoker
{
private Card[] cards;
private int[] value;

Hand(Deck d)
{
value = new int[6];
cards = new Card[5];
for (int x=0; x<5; x++)
{
cards[x] = d.drawFromDeck();
}

int[] ranks = new int[14];
int[] orderedRanks = new int[5];
boolean flush=true, straight=false;
int sameCards=1,sameCards2=1;
int largeGroupRank=0,smallGroupRank=0;
int index=0;
int topStraightValue=0;

for (int x=0; x<=13; x++)
{
ranks[x]=0;
}
for (int x=0; x<=4; x++)
{
ranks[ cards[x].getRank() ]++;
}
for (int x=0; x<4; x++)
{
if ( cards[x].getSuit() != cards[x+1].getSuit() )
flush=false;
}

for (int x=13; x>=1; x--)
{
if (ranks[x] > sameCards)
{
if (sameCards != 1)
//if sameCards was not the default value
{
sameCards2 = sameCards;
smallGroupRank = largeGroupRank;
}

sameCards = ranks[x];
largeGroupRank = x;

} else if (ranks[x] > sameCards2)
{
sameCards2 = ranks[x];
smallGroupRank = x;
}
}

if (ranks[1]==1)
{
orderedRanks[index]=14;
index++;
}

for (int x=13; x>=2; x--)
{
if (ranks[x]==1)
{
orderedRanks[index]=x; //if ace
index++;
}
}
  
for (int x=1; x<=9; x++)
{
if (ranks[x]==1 && ranks[x+1]==1 && ranks[x+2]==1 &&
ranks[x+3]==1 && ranks[x+4]==1)
{
straight=true;
topStraightValue=x+4; //4 above bottom value
break;
}
}

if (ranks[10]==1 && ranks[11]==1 && ranks[12]==1 &&
ranks[13]==1 && ranks[1]==1) //ace high
{
straight=true;
topStraightValue=14; //higher than king
}
  
for (int x=0; x<=5; x++)
{
value[x]=0;
}

if ( sameCards==1 )
{
value[0]=1;
value[1]=orderedRanks[0];
value[2]=orderedRanks[1];
value[3]=orderedRanks[2];
value[4]=orderedRanks[3];
value[5]=orderedRanks[4];
}

if (sameCards==2 && sameCards2==1)
{
value[0]=2;
value[1]=largeGroupRank; //rank of pair
value[2]=orderedRanks[0];
value[3]=orderedRanks[1];
value[4]=orderedRanks[2];
}

if (sameCards==2 && sameCards2==2) //two pair
{
value[0]=3;
//rank of greater pair
value[1]= largeGroupRank>smallGroupRank ? largeGroupRank : smallGroupRank;
value[2]= largeGroupRank<smallGroupRank ? largeGroupRank : smallGroupRank;
value[3]=orderedRanks[0]; //extra card
}

if (sameCards==3 && sameCards2!=2)
{
value[0]=4;
value[1]= largeGroupRank;
value[2]=orderedRanks[0];
value[3]=orderedRanks[1];
}

if (straight && !flush)
{
value[0]=5;
value[1]=;
}

if (flush && !straight)
{
value[0]=6;
value[1]=orderedRanks[0]; //tie determined by ranks of cards
value[2]=orderedRanks[1];
value[3]=orderedRanks[2];
value[4]=orderedRanks[3];
value[5]=orderedRanks[4];
}

if (sameCards==3 && sameCards2==2)
{
value[0]=7;
value[1]=largeGroupRank;
value[2]=smallGroupRank;
}

if (sameCards==4)
{
value[0]=8;
value[1]=largeGroupRank;
value[2]=orderedRanks[0];
}

if (straight && flush)
{
value[0]=9;
value[1]=;
}

}

void display()
{
String s;
switch( value[0] )
{

case 1:
s="high card";
break;
case 2:
s="pair of " + Card.rankAsString(value[1]) + "'s";
break;
case 3:
s="two pair " + Card.rankAsString(value[1]) + " " +
Card.rankAsString(value[2]);
break;
case 4:
s="three of a kind " + Card.rankAsString(value[1]) + "'s";
break;
case 5:
s=Card.rankAsString(value[1]) + " high straight";
break;
case 6:
s="flush";
break;
case 7:
s="full house " + Card.rankAsString(value[1]) + " over " +
Card.rankAsString(value[2]);
break;
case 8:
s="four of a kind " + Card.rankAsString(value[1]);
break;
case 9:
s="straight flush " + Card.rankAsString(value[1]) + " high";
break;
default:
s="error in Hand.display: value[0] contains invalid value";
}
s = " " + s;
System.out.println(s);
}

void displayAll()
{
for (int x=0; x<5; x++)
System.out.println(cards[x]);
}

int compareTo(Hand that)
{
for (int x=0; x<6; x++)
{
if (this.value[x]>that.value[x])
return 1;
else if (this.value[x]<that.value[x])
return -1;
}
return 0;
}
}