How to develop Septem-Octo (Card Game) in Java?

Card-Game

Septem-Octo (Card Game) Requirements:

This game is played using 30 playing cards, Clubs (8 to 10, J, Q, K, A), Diamonds (7 to 10, J, Q, K, A), Hearts (8 to 10, J, Q, K, A) and Spades (7 to 10, J, Q, K, A). The game setup is as follows:
Open card: A card is said to be open, if the card is visible to the player.
This game consists of two players, a human player and the computer

First decide which player will start the game

Distribute 15 cards to each player. The 15 cards are divided into three sets
1. Hand cards: The player will hold five cards in their hand. The player can play these cards.
2. Table open cards: These cards will be on the table and can be seen and played by the player.
3. Table closed cards. These cards are placed underneath the open cards and cannot be seen or played until the corresponding open card is played.

Human player can only view the computer’s open table cards.

Game Play

The player who starts the game should decide the trump suit. In general, the trump suit is decided based on the count of suits the player has among hand cards and table open cards. For example, among hand cards and table open cards, if the player has 4 spades, 2 diamonds, 2 clubs and 2 hearts, the player should select spades as the trump suit.
–>A round is played in the following manner:
1. One who plays the round first can start with any card from the open cards. Let us call this player as First Player, and the card he/she played as First Player Card.
2. The other player has the following options to play a card:
(a) If the second player has the card of the same suit that matches with the suit of the first player card, then he/she should always play a card from that suit.
(b) If the second player does not have a card of the same suit that matches with the suit of the first player card, then he/she is allowed to play a trump suit card.
(c) If the above conditions are not met, then the second player can play any card.
3. Winner of the round is decided as follows:
(a) If the first player card and second player card are of same suit, then the player with highest card value is the winner
(b) If the first player card and second player card are of different suit, and if either player played a trump suit card, then the winner is the player who played the trump suit card.
(c) If the first player card and the second player card are of a different suit and none of them played a trump suit card, then the winner is the player who started the round.

The player who wins the round will start the next round

Solution:

Dashboard.java
package examples;

import java.awt.Button;
import java.awt.HeadlessException;
import java.awt.Image;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.plaf.basic.BasicArrowButton;

public class Dashboard extends javax.swing.JFrame {
int computerturn = 0;ImageIcon[] ii;
    static Dashboard dashbrd ;
     Path currentRelativePath = Paths.get(“”);
     String s = currentRelativePath.toAbsolutePath().toString();
     
   
       Map<String, ImageIcon> iconMap  ;
     String[] ranks = new  String[28];
    public Dashboard() throws IOException {
        initComponents();  int i=0;
      
        iconMap = new HashMap<String, ImageIcon>();
           File  directory = new File(s+”/src/cards”);
              ii  = new ImageIcon[directory.listFiles().length];
           System.out.println(“Current relative path is: ” + s);
         for (File file : directory.listFiles())
{
    // could also use a FileNameFilter
    if(file.getName().toLowerCase().endsWith(“.jpg”))
    {
        iconMap.put(file.getName(), new ImageIcon(file.getPath()));
       ranks[i]= file.getName();
    ImageIcon img =  new ImageIcon(file.getPath());
 ii[i] =  img;// ImageIcon(file.getPath());
    i++;
    }
}
resizecomp(ii , ranks);
    resizehum(ii , ranks)   ;
   
       dashbrd = this;
       setcomputerOpencard(0 , null);
        sethumanOpencard(0 , null);
          pl = new play(humancards,compcards ,ii);
    } play pl;
    JButton[] btn  ;
       
        String[] compcards = new String[15];
               String[] humancards = new String[15];
        JButton[] hiddencomp  ;// = new JButton[10];
        String[] hearts = new String[5];
        String[] spades = new String[5];
        String[] diamonds  = new String[5];
        
        public void sethumanOpencard(int index , String name){
    
           
    
    }
        
    public void setcomputerOpencard(int index , String name){
    
       
    
    }
    
    
    public void resizecomp(ImageIcon[] iic , String[] rank ){
   hiddencomp  = new JButton[11];
    btn = new JButton[15];
  hiddencomp[0] = comp_closecard;
  hiddencomp[2] = comp_closecard29;
  hiddencomp[3] = comp_closecard2;
  hiddencomp[4] = comp_closecard3;
  hiddencomp[5] = comp_closecard4;
  hiddencomp[6] = comp_closecard5;
      hiddencomp[7] =  comp_closecard14;
    hiddencomp[8]=    comp_closecard26;
   hiddencomp[9]=    comp_closecard27;
   hiddencomp[10]=    comp_closecard28;
 
    btn[0]=   new JButton();//comp_closecard;
    btn[1]=   new JButton();//comp_closecard29;
    btn[2]=   new JButton();// comp_closecard2;
    btn[3]=    new JButton();//comp_closecard3;
    btn[4]=    new JButton();//comp_closecard4;
    btn[5]=   new JButton();// comp_closecard5;
    btn[6]=    comp_closecard6;
    btn[7]=    comp_closecard7;
    btn[8]=    comp_closecard8;
    btn[9]=    comp_closecard9;
    btn[10]=   comp_closecard11;
    btn[11]=    comp_closecard14;
    btn[12]=    comp_closecard26;
   btn[13]=    comp_closecard27;
   btn[14]=    comp_closecard28;
     for(int p= 0 ; p< 15 ; p++){
     
     compcards[p] = rank[p];
     }
   
       int scale = 4;
        System.out.print(btn.length);
    for(int i =0 ; i < btn.length-4 ; i++){
int width = iic[i].getIconWidth();
int newWidth = width / scale;
   btn[i].setText(rank[i]);
   
   btn[i].setIcon(new ImageIcon(iic[i].getImage().getScaledInstance(newWidth, -1,
            java.awt.Image.SCALE_SMOOTH)));
    
    }
    
    }
    
 public void resizehum(ImageIcon[] ii,String[] rank){
   
   
    JButton[]  btn2 = new JButton[16];
 
    btn2[0]=    hum_closecard1;
    btn2[1]=    hum_closecard13;
    btn2[2]=    hum_closecard15;
    btn2[3]=    hum_closecard17;
    btn2[4]=    hum_closecard18;
    btn2[5]=    hum_closecard19;
    btn2[6]=    hum_closecard21;
    btn2[7]=    hum_closecard20;
    btn2[8]=    hum_closecard11;
    btn2[9]=    hum_closecard12;
    btn2[10]=   hum_closecard19;
    btn2[11]=   hum_closecard24;
    btn2[12]=   hum_closecard23;
    btn2[13]=   hum_closecard25;
    btn2[14]=   hum_closecard16;
    btn2[15]=   hum_closecard22;
    int u= 0;
     for(int p= 15 ; p>0 ; p–){
     
     humancards[u] = rank[p];
     u++;
     }
   
   int j = 0 ;
       int scale = 4;
 
    for(int i =ii.length-1 ; i > 0; i–){
int width = ii[i].getIconWidth();
int newWidth = width / scale;
if(j<16){
   btn2[j].setText(rank[i]);
btn2[j].setIcon(new ImageIcon(ii[i].getImage().getScaledInstance(newWidth, -1,
            java.awt.Image.SCALE_SMOOTH)));
j++;}
      
    
    }
    
    }

    

    // <editor-fold defaultstate=”collapsed” desc=”Generated Code”>//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jFrame2 = new javax.swing.JFrame();
        comp_closecard = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        comp_closecard2 = new javax.swing.JButton();
        comp_closecard3 = new javax.swing.JButton();
        comp_closecard4 = new javax.swing.JButton();
        comp_closecard5 = new javax.swing.JButton();
        comp_closecard6 = new javax.swing.JButton();
        comp_closecard7 = new javax.swing.JButton();
        comp_closecard8 = new javax.swing.JButton();
        comp_closecard9 = new javax.swing.JButton();
        comp_closecard14 = new javax.swing.JButton();
        hum_closecard11 = new javax.swing.JButton();
        hum_closecard12 = new javax.swing.JButton();
        hum_closecard16 = new javax.swing.JButton();
        hum_closecard19 = new javax.swing.JButton();
        hum_closecard20 = new javax.swing.JButton();
        hum_closecard21 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        hum_closecard22 = new javax.swing.JButton();
        hum_closecard23 = new javax.swing.JButton();
        hum_closecard24 = new javax.swing.JButton();
        hum_closecard25 = new javax.swing.JButton();
        comp_closecard26 = new javax.swing.JButton();
        comp_closecard27 = new javax.swing.JButton();
        comp_closecard28 = new javax.swing.JButton();
        comp_closecard29 = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        comp_closecard11 = new javax.swing.JButton();
        hum_closecard18 = new javax.swing.JButton();
        hum_closecard17 = new javax.swing.JButton();
        hum_closecard1 = new javax.swing.JButton();
        hum_closecard15 = new javax.swing.JButton();
        hum_closecard13 = new javax.swing.JButton();

        org.jdesktop.layout.GroupLayout jFrame2Layout = new org.jdesktop.layout.GroupLayout(jFrame2.getContentPane());
        jFrame2.getContentPane().setLayout(jFrame2Layout);
        jFrame2Layout.setHorizontalGroup(
            jFrame2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 400, Short.MAX_VALUE)
        );
        jFrame2Layout.setVerticalGroup(
            jFrame2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 300, Short.MAX_VALUE)
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle(“Card Game”);

        comp_closecard.setName(“”); // NOI18N

        jLabel1.setText(“Score”);

        jLabel2.setText(“0”);

        comp_closecard2.setName(“”); // NOI18N

        comp_closecard3.setName(“”); // NOI18N

        comp_closecard4.setName(“”); // NOI18N

        comp_closecard5.setName(“”); // NOI18N
        comp_closecard5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comp_closecard5ActionPerformed(evt);
            }
        });

        comp_closecard6.setName(“”); // NOI18N
        comp_closecard6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comp_closecard6ActionPerformed(evt);
            }
        });

        comp_closecard7.setName(“”); // NOI18N
        comp_closecard7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comp_closecard7ActionPerformed(evt);
            }
        });

        comp_closecard8.setName(“”); // NOI18N
        comp_closecard8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comp_closecard8ActionPerformed(evt);
            }
        });

        comp_closecard9.setName(“”); // NOI18N
        comp_closecard9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comp_closecard9ActionPerformed(evt);
            }
        });

        comp_closecard14.setIcon(new javax.swing.ImageIcon(getClass().getResource(“/cards/front.jpg”))); // NOI18N
        comp_closecard14.setName(“”); // NOI18N

        hum_closecard11.setName(“”); // NOI18N
        hum_closecard11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                hum_closecard11ActionPerformed(evt);
            }
        });

        hum_closecard12.setName(“”); // NOI18N
        hum_closecard12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                hum_closecard12ActionPerformed(evt);
            }
        });

        hum_closecard16.setName(“”); // NOI18N
        hum_closecard16.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                hum_closecard16ActionPerformed(evt);
            }
        });

        hum_closecard19.setName(“”); // NOI18N
        hum_closecard19.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                hum_closecard19ActionPerformed(evt);
            }
        });

        hum_closecard20.setName(“”); // NOI18N
        hum_closecard20.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                hum_closecard20ActionPerformed(evt);
            }
        });

        hum_closecard21.setName(“”); // NOI18N
        hum_closecard21.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                hum_closecard21ActionPerformed(evt);
            }
        });

        jLabel3.setText(“==================================================================================”);

        hum_closecard22.setName(“”); // NOI18N
        hum_closecard22.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                hum_closecard22ActionPerformed(evt);
            }
        });

        hum_closecard23.setName(“”); // NOI18N
        hum_closecard23.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                hum_closecard23ActionPerformed(evt);
            }
        });

        hum_closecard24.setName(“”); // NOI18N
        hum_closecard24.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                hum_closecard24ActionPerformed(evt);
            }
        });

        hum_closecard25.setName(“”); // NOI18N
        hum_closecard25.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                hum_closecard25ActionPerformed(evt);
            }
        });

        comp_closecard26.setIcon(new javax.swing.ImageIcon(getClass().getResource(“/cards/front.jpg”))); // NOI18N
        comp_closecard26.setName(“”); // NOI18N

        comp_closecard27.setIcon(new javax.swing.ImageIcon(getClass().getResource(“/cards/front.jpg”))); // NOI18N
        comp_closecard27.setName(“”); // NOI18N

        comp_closecard28.setIcon(new javax.swing.ImageIcon(getClass().getResource(“/cards/front.jpg”))); // NOI18N
        comp_closecard28.setName(“”); // NOI18N

        comp_closecard29.setIcon(new javax.swing.ImageIcon(getClass().getResource(“/cards/front.jpg”))); // NOI18N
        comp_closecard29.setName(“”); // NOI18N
        comp_closecard29.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comp_closecard29ActionPerformed(evt);
            }
        });

        jLabel4.setText(“Score”);

        jLabel5.setText(“0”);

        jLabel6.setText(“Computer”);

        jLabel7.setText(“Human start 1st”);

        comp_closecard11.setName(“”); // NOI18N
        comp_closecard11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comp_closecard11ActionPerformed(evt);
            }
        });

        hum_closecard18.setName(“”); // NOI18N
        hum_closecard18.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                hum_closecard18ActionPerformed(evt);
            }
        });

        hum_closecard17.setName(“”); // NOI18N
        hum_closecard17.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                hum_closecard17ActionPerformed(evt);
            }
        });

        hum_closecard1.setName(“”); // NOI18N
        hum_closecard1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                hum_closecard1ActionPerformed(evt);
            }
        });

        hum_closecard15.setName(“”); // NOI18N
        hum_closecard15.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                hum_closecard15ActionPerformed(evt);
            }
        });

        hum_closecard13.setName(“”); // NOI18N
        hum_closecard13.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                hum_closecard13ActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jLabel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 758, Short.MAX_VALUE)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .add(jLabel6)
                                .add(91, 91, 91)
                                .add(jLabel1)
                                .add(46, 46, 46)
                                .add(jLabel2))
                            .add(layout.createSequentialGroup()
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(layout.createSequentialGroup()
                                        .add(comp_closecard27, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                        .add(comp_closecard29, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                    .add(layout.createSequentialGroup()
                                        .add(comp_closecard26, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                        .add(comp_closecard28, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(comp_closecard14, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                        .add(42, 42, 42)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                                .add(comp_closecard5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(comp_closecard4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(comp_closecard, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(comp_closecard3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(comp_closecard2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                                .add(comp_closecard11, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(comp_closecard9, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(comp_closecard8, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(comp_closecard7, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(comp_closecard6, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
                    .add(jLabel7)
                    .add(layout.createSequentialGroup()
                        .add(32, 32, 32)
                        .add(jLabel4)
                        .add(46, 46, 46)
                        .add(jLabel5)))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                            .add(hum_closecard16, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(79, 79, 79))
                        .add(layout.createSequentialGroup()
                            .add(hum_closecard24, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                .add(hum_closecard25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(hum_closecard23, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
                    .add(hum_closecard22, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 79, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 77, Short.MAX_VALUE)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(hum_closecard12, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(hum_closecard11, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(hum_closecard21, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(hum_closecard20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(hum_closecard19, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(layout.createSequentialGroup()
                        .add(hum_closecard18, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(hum_closecard17, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(hum_closecard1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(hum_closecard15, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(hum_closecard13, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .add(128, 128, 128))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .addContainerGap()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel1)
                            .add(jLabel2)))
                    .add(jLabel6))
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(layout.createSequentialGroup()
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                    .add(comp_closecard6, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE)
                                    .add(comp_closecard8, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE)
                                    .add(comp_closecard7, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE)
                                    .add(comp_closecard9, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE)
                                    .add(org.jdesktop.layout.GroupLayout.TRAILING, comp_closecard11, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(comp_closecard2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 107, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(comp_closecard, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 107, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(comp_closecard3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 107, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(comp_closecard4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 107, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(comp_closecard5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 107, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                            .add(layout.createSequentialGroup()
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                    .add(comp_closecard26, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 107, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(comp_closecard28, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                    .add(comp_closecard29, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 107, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(comp_closecard27, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 107, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))))
                    .add(layout.createSequentialGroup()
                        .add(40, 40, 40)
                        .add(comp_closecard14, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 107, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .add(35, 35, 35)
                .add(jLabel3)
                .add(18, 18, 18)
                .add(jLabel7)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel4)
                    .add(jLabel5))
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(hum_closecard22, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 118, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(hum_closecard19, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 107, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(hum_closecard21, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 107, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(hum_closecard20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 107, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(hum_closecard11, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 107, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(hum_closecard12, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 107, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 10, Short.MAX_VALUE)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(hum_closecard16, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 107, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(hum_closecard24, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 107, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(hum_closecard25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 107, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(hum_closecard13, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 107, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(hum_closecard1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 107, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(hum_closecard15, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 107, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(hum_closecard17, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 107, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(hum_closecard18, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 107, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(hum_closecard23, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 107, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(97, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void comp_closecard29ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comp_closecard29ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_comp_closecard29ActionPerformed

    private void comp_closecard11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comp_closecard11ActionPerformed
     
     String s=   comp_closecard11.getText();
    pl.playcom(s );
 

// TODO add your handling code here:
    }//GEN-LAST:event_comp_closecard11ActionPerformed

    private void comp_closecard9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comp_closecard9ActionPerformed

 
     String s=   comp_closecard9.getText();
    pl.playcom(s );
    
 
        // TODO add your handling code here:
    }//GEN-LAST:event_comp_closecard9ActionPerformed

    private void comp_closecard8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comp_closecard8ActionPerformed

 
     String s=   comp_closecard8.getText();
      pl.playcom(s );
    
 

        // TODO add your handling code here:
    }//GEN-LAST:event_comp_closecard8ActionPerformed

    private void comp_closecard7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comp_closecard7ActionPerformed

 
     String s=   comp_closecard7.getText();
    pl.playcom(s );
 

        // TODO add your handling code here:
    }//GEN-LAST:event_comp_closecard7ActionPerformed

    private void comp_closecard6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comp_closecard6ActionPerformed
 
   
 

        // TODO add your handling code here:
    }//GEN-LAST:event_comp_closecard6ActionPerformed

    private void comp_closecard5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comp_closecard5ActionPerformed

    
        // TODO add your handling code here:
    }//GEN-LAST:event_comp_closecard5ActionPerformed
public void score(String lbl){
if(lbl.contains(“h”)){
  int i = Integer.parseInt(jLabel5.getText());
    i = i + 10;
jLabel5.setText(String.valueOf(i));

}
else if (lbl.contains(“e”)){

  int a = Integer.parseInt(jLabel2. getText());
int s = Integer.parseInt(jLabel5.getText());
if(a > s){
JOptionPane.showMessageDialog(jFrame2,”computer wins”,
    “Result”,    
    JOptionPane.PLAIN_MESSAGE);
}
else if (a==s){

JOptionPane.showMessageDialog(jFrame2,”Equal Tie”,
    “Result”,    
    JOptionPane.PLAIN_MESSAGE);
}
else {

JOptionPane.showMessageDialog(jFrame2,”Human wins”,
    “Result”,    
    JOptionPane.PLAIN_MESSAGE);

}
  dispose();
}
else{
int i = Integer.parseInt(jLabel2. getText());
    i = i + 10;
jLabel2.setText(String.valueOf(i));

}

          
}

    private void hum_closecard12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hum_closecard12ActionPerformed
String s=    hum_closecard12.getText();
      //  hum_closecard12.setIcon(null);
          String sc =    pl.playhuman(s );
          score(sc);
         hum_closecard12.setEnabled(false);
         

// TODO add your handling code here:
    }//GEN-LAST:event_hum_closecard12ActionPerformed

    private void hum_closecard18ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hum_closecard18ActionPerformed
 
        
        String s=    hum_closecard18.getText();
 hum_closecard18.setEnabled(false);
      String sc =    pl.playhuman(s );
      score(sc);
 
        // TODO add your handling code here:
    }//GEN-LAST:event_hum_closecard18ActionPerformed

    private void hum_closecard11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hum_closecard11ActionPerformed

        String s=    hum_closecard11.getText();
       // hum_closecard11.setIcon(null);
        String sc =    pl.playhuman(s );
      score(sc);
         hum_closecard11.setEnabled(false);
       // TODO add your handling code here:
    }//GEN-LAST:event_hum_closecard11ActionPerformed

    private void hum_closecard21ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hum_closecard21ActionPerformed
String s=    hum_closecard21.getText();
   hum_closecard21.setEnabled(false);
      String sc =    pl.playhuman(s );
      score(sc);       // TODO add your handling code here:
    }//GEN-LAST:event_hum_closecard21ActionPerformed

    private void hum_closecard20ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hum_closecard20ActionPerformed
String s=    hum_closecard20.getText();
   hum_closecard20.setEnabled(false);
       String sc =    pl.playhuman(s );
      score(sc);    
        

// TODO add your handling code here:
    }//GEN-LAST:event_hum_closecard20ActionPerformed

    private void hum_closecard19ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hum_closecard19ActionPerformed
String s=    hum_closecard19.getText();
   hum_closecard19.setEnabled(false);
      String sc =    pl.playhuman(s );
      score(sc);      // TODO add your handling code here:
    }//GEN-LAST:event_hum_closecard19ActionPerformed

    private void hum_closecard17ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hum_closecard17ActionPerformed
String s=    hum_closecard17.getText();
  hum_closecard17.setEnabled(false);
     String sc =    pl.playhuman(s );
      score(sc);       
      

// TODO add your handling code here:
    }//GEN-LAST:event_hum_closecard17ActionPerformed

    private void hum_closecard1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hum_closecard1ActionPerformed
String s=    hum_closecard1.getText();
 
       String sc =    pl.playhuman(s );
      score(sc);     
      hum_closecard1.setEnabled(false);

// TODO add your handling code here:
    }//GEN-LAST:event_hum_closecard1ActionPerformed

    private void hum_closecard15ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hum_closecard15ActionPerformed
String s=    hum_closecard15.getText();
 
       String sc =    pl.playhuman(s );
      score(sc);      
            hum_closecard15.setEnabled(false);

// TODO add your handling code here:
    }//GEN-LAST:event_hum_closecard15ActionPerformed

    private void hum_closecard13ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hum_closecard13ActionPerformed
String s=    hum_closecard13.getText();
 
      String sc =    pl.playhuman(s );
      score(sc);     
  hum_closecard13.setEnabled(false);

// TODO add your handling code here:
    }//GEN-LAST:event_hum_closecard13ActionPerformed

    private void hum_closecard22ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hum_closecard22ActionPerformed
String s=    hum_closecard22.getText();
 
       String sc =    pl.playhuman(s );
      score(sc);   
      
hum_closecard22.setEnabled(false);
// TODO add your handling code here:
    }//GEN-LAST:event_hum_closecard22ActionPerformed

    private void hum_closecard16ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hum_closecard16ActionPerformed
String s=    hum_closecard16.getText();
 hum_closecard16.setEnabled(false);  
       String sc =    pl.playhuman(s );
      score(sc);      // TODO add your handling code here:
    }//GEN-LAST:event_hum_closecard16ActionPerformed

    private void hum_closecard25ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hum_closecard25ActionPerformed
String s=    hum_closecard25.getText();
 hum_closecard25.setEnabled(false);   
       pl.playhuman(s );      // TODO add your handling code here:
    }//GEN-LAST:event_hum_closecard25ActionPerformed

    private void hum_closecard23ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hum_closecard23ActionPerformed
       String s=    hum_closecard23.getText();
 
       String sc =    pl.playhuman(s );
      score(sc);   
      hum_closecard23.setEnabled(false);  

// TODO add your handling code here:
    }//GEN-LAST:event_hum_closecard23ActionPerformed

    private void hum_closecard24ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hum_closecard24ActionPerformed
String s=    hum_closecard24.getText();
 
       String sc =    pl.playhuman(s );
      score(sc);
   hum_closecard24.setEnabled(false);  
// TODO add your handling code here:
    }//GEN-LAST:event_hum_closecard24ActionPerformed
       
   

     
        
    public static void main(String args[]) throws IOException {
        
      
       
       

//       dashbrd.clubs = new Image[13];
//        dashbrd.hearts = new Image[13];
//        dashbrd.spades = new Image[13];
//        dashbrd.diamonds = new Image[13];
             
      
        
       
        try {
            javax.swing.UIManager.LookAndFeelInfo[] installedLookAndFeels=javax.swing.UIManager.getInstalledLookAndFeels();
            for (int idx=0; idx<installedLookAndFeels.length; idx++)
                if (“Nimbus”.equals(installedLookAndFeels[idx].getName())) {
                    javax.swing.UIManager.setLookAndFeel(installedLookAndFeels[idx].getClassName());
                    break;
                }
            
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Dashboard.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Dashboard.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Dashboard.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Dashboard.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    new Dashboard().setVisible(true);
                    
                } catch (IOException ex) {
                    Logger.getLogger(Dashboard.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }
    
    // Variables declaration – do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton comp_closecard;
    private javax.swing.JButton comp_closecard11;
    private javax.swing.JButton comp_closecard14;
    private javax.swing.JButton comp_closecard2;
    private javax.swing.JButton comp_closecard26;
    private javax.swing.JButton comp_closecard27;
    private javax.swing.JButton comp_closecard28;
    private javax.swing.JButton comp_closecard29;
    private javax.swing.JButton comp_closecard3;
    private javax.swing.JButton comp_closecard4;
    private javax.swing.JButton comp_closecard5;
    private javax.swing.JButton comp_closecard6;
    private javax.swing.JButton comp_closecard7;
    private javax.swing.JButton comp_closecard8;
    private javax.swing.JButton comp_closecard9;
    private javax.swing.JButton hum_closecard1;
    private javax.swing.JButton hum_closecard11;
    private javax.swing.JButton hum_closecard12;
    private javax.swing.JButton hum_closecard13;
    private javax.swing.JButton hum_closecard15;
    private javax.swing.JButton hum_closecard16;
    private javax.swing.JButton hum_closecard17;
    private javax.swing.JButton hum_closecard18;
    private javax.swing.JButton hum_closecard19;
    private javax.swing.JButton hum_closecard20;
    private javax.swing.JButton hum_closecard21;
    private javax.swing.JButton hum_closecard22;
    private javax.swing.JButton hum_closecard23;
    private javax.swing.JButton hum_closecard24;
    private javax.swing.JButton hum_closecard25;
    private javax.swing.JFrame jFrame2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    // End of variables declaration//GEN-END:variables
    
}

Play.java

package examples;

import java.util.Random;
import javax.swing.ImageIcon;

public class play {
static final Integer[] VALUE = {1,2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
int humanplay = 0;
int computerplay = 0;
String[] Spades = new String[10];
String[] Hearts = new String[10];
String[] Diamonds = new String[10];
String[] Clubs = new String[10];
String[] human = new String[15];

String[] comp = new String[15];
ImageIcon[] all = new ImageIcon[30];
play(  String[] humanc , String[] compc , ImageIcon[] ranks){

human=humanc;

comp = compc;
all = ranks;
}
public String playcom(String card){
computerplay++; String nm = null ;
String suit = getsuit(card);
String[] matchsuit = new String[5];
for(int i = 0 ; i< 15 ; i ++){

if(suit == getsuit(comp[i])){

nm = checkWin(comp[i] , card , “s”);
comp[i] = “y”;

}

}
if(nm == null){

int g =   getR();

nm = checkWin(comp[g] , card , “d”);

}

return nm;

}
public static boolean isInteger(String s) {
return isInteger(s,10);
}
int getR(){
Random rn = new Random();
int g =  rn.nextInt(14 – 0 + 1) + 0;
for(int i = 0 ; i < 15 ; i++){
if(comp[i] != “y”){

return i;

}

}
if(comp[g] == “y”){

}
else {

return g;
}
return g;
}

int getRb(){
Random rn = new Random();
int g =  rn.nextInt(14 – 0 + 1) + 0;
if(human[g] == “y”){
getR();
}
else {

return g;
}
return g;
}

public static boolean isInteger(String s, int radix) {
if(s.isEmpty()) return false;
for(int i = 0; i < s.length(); i++) {
if(i == 0 && s.charAt(i) == ‘-‘) {
if(s.length() == 1) return false;
else continue;
}
if(Character.digit(s.charAt(i),radix) < 0) return false;
}
return true;
}
String checkWin(String sysc , String hum , String TURN){
if (TURN == “d”){
return “s”;

}
if (TURN == “s”){
String Sf = “s” , Ss = “s”,Hf , Hs;
if(sysc.length()==6 ){

Sf =    String.valueOf(sysc.charAt(0));
Ss = String.valueOf(hum.charAt(0));
}
if(sysc.length()==7 && sysc.length()==7){

Hf =  String.valueOf(sysc.charAt(0)+sysc.charAt(1));
Hs =  String.valueOf(hum.charAt(0)+hum.charAt(1));
int m,n;
m = Integer.parseInt(Hf);
n = Integer.parseInt(Hs);

return “h”;

}
boolean chck = isInteger(Sf);
boolean chck2 = isInteger(Ss);
if(chck== true && chck2 == true){

int m,n;
m = Integer.parseInt(Sf);
n = Integer.parseInt(Ss);
if(m>n){

return “sys”;
}
else if (m==n){
return “h”;

}
else{
return “h”;

}
}
else {
if(chck== true && chck2 == false)
{

return “h”;

}

if (Sf == “A”){ return “S”;}
if (Ss == “A”){ return “h”;}
if (Sf == “J” ){
if (Ss == “A”){ return “h”;}
if (Ss == “J”){ return “s”;}
if (Ss == “Q”){ return “h”;}
if (Ss == “K”){ return “h”;}
return “S”;
}
if (Sf == “Q” ){
if (Ss == “A”){ return “h”;}
if (Ss == “J”){ return “s”;}
if (Ss == “Q”){ return “s”;}
if (Ss == “K”){ return “h”;}
return “S”;
}
if (Sf == “k” ){
if (Ss == “A”){ return “h”;}
if (Ss == “J”){ return “s”;}
if (Ss == “Q”){ return “s”;}
if (Ss == “K”){ return “s”;}
return “S”;
}

}
}
else{

String Sf = “s” , Ss = “s”,Hf , Hs;
if(sysc.length()==6 ){

Sf =    String.valueOf(sysc.charAt(0));
Ss = String.valueOf(hum.charAt(0));
}
if(sysc.length()==7 && sysc.length()==7){

Hf =  String.valueOf(sysc.charAt(0)+sysc.charAt(1));
Hs =  String.valueOf(hum.charAt(0)+hum.charAt(1));
int m,n;
m = Integer.parseInt(Hf);
n = Integer.parseInt(Hs);

return “h”;

}
boolean chck = isInteger(Sf);
boolean chck2 = isInteger(Ss);
if(chck){

int m,n;
m = Integer.parseInt(Sf);
n = Integer.parseInt(Ss);
if(m>n){

return “sys”;
}
else if (m==n){
return “h”;

}
else{
return “h”;

}
}
else {

if (Ss == “A”){ return “h”;}
if (Sf == “A”){ return “s”;}
if (Ss == “J” ){
if (Sf == “A”){ return “s”;}
if (Sf == “J”){ return “h”;}
if (Sf == “Q”){ return “s”;}
if (Sf == “K”){ return “s”;}
return “h”;
}
if (Ss == “Q” ){
if (Sf == “A”){ return “s”;}
if (Sf == “J”){ return “h”;}
if (Sf == “Q”){ return “h”;}
if (Sf == “K”){ return “s”;}
return “h”;
}
if (Ss == “k” ){
if (Sf == “A”){ return “s”;}
if (Sf == “J”){ return “h”;}
if (Sf == “Q”){ return “h”;}
if (Sf == “K”){ return “h”;}
return “h”;
}

}

}
return “h”;

}
public String playhuman(String card){
humanplay++;
if(humanplay==7){
return “e”;

}
String nm = null;
for(int i = 0 ; i< 15 ; i ++){

if(human[i] == card){

nm =   playcom(card);
human[i] = “y”;
}

}
if(nm == null) {

int g =   getRb();

nm = playcom(card);

}
else {

nm=”h”;

}

return nm;
}
String  getsuit(String  crd){
if(crd.toUpperCase().contains(“S”))
{ return “SPADE”;}
if(crd.toUpperCase().contains(“D”))
{ return “Diamonds”;}
if(crd.toUpperCase().contains(“C”))
{ return “Clubs”;}
if(crd.toUpperCase().contains(“H”))
{ return “human”;}
return “NO”;
}

}

Output Screens:

output java card game

LEAVE A REPLY

Please enter your comment!
Please enter your name here