Need exe file to open console

171 views Asked by At

I am a student of 2 months so bear with me here.

I am trying to show my friend a Rock, Paper, Scissors game in action. I've successfully created RockPaperScissors.exe using Launch4j.

Now when I click the game's executable file I get the console to open. But when my friend tries to do so, he gets the console with no words in it, if he tries to type it closes.

Is it possible to have an executable file force the console up? Do I need to change some part of my code in order to have that happen?

Code is below in case I need to add something to make this work.

import java.util.Scanner;
import java.util.Random;

public class RockPaperScissors 
{

  /***** CONSTANT SECTION *****/

  public static void main(String[] args)
  {
    /***** DECLARATION SECTION *****/
    Scanner keyboard;
    Random rndGen;
    char  computerChoice;
    int playerScore, compScore;
    int winner, compInt;
    String name;
    String userChoice;

    /***** INITIALIZATION SECTION *****/
    keyboard = new Scanner(System.in);
    rndGen = new Random();
    
    computerChoice = ' ';
    winner = -1;
    compInt = -1;
    
    playerScore = 0;
    compScore = 0;

    /***** INTRO SECTION *****/
    System.out.print("What is your name? ");
    name = keyboard.next();
    System.out.println("\nHi " + name + ".");
    System.out.println("\nLet's play Rock, Paper, Scissors!");
    System.out.println("Best out of 3 wins.");

    /***** INPUT SECTION *****/
    while (playerScore < 2 && compScore < 2)
    {
    System.out.print("\nEnter your choice. Type R for rock, P for paper, or S for scissors: ");
    
    
        //takes a char entry and changes it into a string, upper cases the entry, and then take the first letter of the string
    userChoice = keyboard.next();
    userChoice = userChoice.toUpperCase();
    
    while (!(userChoice.equals("R") || userChoice.equals("P") || userChoice.equals("S")))
            {
        System.out.println("Invalid entry.");
        System.out.println("");
        System.out.print("Enter your choice. Type R for rock, P for paper, or S for scissors: ");
        userChoice = keyboard.next();
        userChoice = userChoice.toUpperCase();
            }
    
    /***** PROCESSING SECTION *****/
    
    compInt = rndGen.nextInt(3);
    
    if (compInt == 0)
      {
        computerChoice = 'R';
      }
    else if (compInt == 1)
      {
        computerChoice = 'P';
      }
    else
      {
        computerChoice = 'S';
      }

      winner = RockPaperScissors.decideWinner(userChoice,computerChoice);


    /***** OUTPUT SECTION *****/
    System.out.printf(name + " chose %s%nComputer chose %c%n",userChoice,computerChoice);
    
    switch(winner)
    {
      case 0: System.out.println("It's a tie!");
      break;
      case 1: System.out.println(name + " wins!");
      playerScore = playerScore + 1;
      break;
      case 2: System.out.println("Computer won!");
      compScore = compScore + 1;
      break;
      default: System.out.println("Invalid choice. Try again");
      break;  
    }
    System.out.println(name + ": " + playerScore + ", Computer: " + compScore);
    
    }
    if (playerScore > compScore)
    {
        System.out.println("\n" + name + " is the winner!!!");
    }
    else
    {
        System.out.println("\nSorry, the computer wins this time.");
    }
    keyboard.close();
    System.out.println("Thanks for playing!");
  }
  /***** STATIC METHODS *****/
    //Given two characters (R, P or S) determines //winner user rock paper scissors rules. Error check
  //done in main
    public static int decideWinner(String p1,char p2)
    {
    
    String combo;
    combo = String.format("%s%c",p1,p2);
    
        if ((combo.equals("RS")) || (combo.equals("PR")) || (combo.equals("SP")))
        {
            
            return 1;
        }
        else if ((combo.equals("RP")) || (combo.equals("PS")) || (combo.equals("SR")))
        {
            
            return 2;
        }
        else if ((combo.equals("PP")) || (combo.equals("SS")) || (combo.equals("RR")))
        {
      
            return 0;
        }
        else
        {
      
            return -1;
        }
        
        
    
    }
    
    
}
0

There are 0 answers