0

I have made a .jar file out of this code and I want to be able to click on it and have it run. What needs to be done?

import javax.swing.JOptionPane;

public class HeadsVsTails {
public static void main(String[] args){

    int value = 0;
    int gameToken = 20;
    int win = 0;
    int lose = 0;

    while(gameToken > 0) {

        gameToken = --gameToken;

        int headsOrTails = (int)(Math.random() * 10); 

        if(headsOrTails >= 5)
            value = 1;
        else 
            value = 0;

        String userInput = JOptionPane.showInputDialog(null , "enter heads or tails for your guess");
        char lastChar = userInput.charAt(3);

        if(value == 1 && lastChar == 'd') {
            // a win

            win = ++win;

            JOptionPane.showMessageDialog(null, "you guessed right\n" + "  " + "wins: " + win 
            + " \n" + " loss's:" + lose + "\n" + "tokens left:" + gameToken);
            } 
        else if ( value == 1 && lastChar == 'l'){
            //a lose

            lose = ++ lose;

            JOptionPane.showMessageDialog(null, "oh im sorry thats a not right\n" + " " + "wins:" + win 
            + "\n" + "loss's:" + lose + "\n" + "tokens left:" + gameToken);

        }
        else if (value == 0 && lastChar == 'd'){
            //a lose

            lose = ++ lose;

            JOptionPane.showMessageDialog(null, "oh im sorry thats a not right\n" + " " + "wins:" + win 
            + "\n" + "loss's:" + lose + "\n" + "tokens left:" + gameToken);

        }
        else if (value == 0 && lastChar == 'l'){
            // a win

                            win = ++win;

            JOptionPane.showMessageDialog(null, "you guessed right\n" + "  " + "wins: " + win 
            + " \n" + " loss's:" + lose + "\n" + "tokens left:" + gameToken);
            }
        }

        }
    }

I know this code probably looks messy however all it does is give a user 20 changes to guess what side the coin lands on and then keeps track of how well they did. I can run it in terminal and it works but I want a file on my desktop I can just click. what needs to be done?

thank you in advance

pawsome
  • 29
  • 6

0 Answers0