title: Java Dice Game - Choosing who starts a game based on dice roll and taking turns
body: <p>Prompt: "Write a program to play the pig game against the computer. At each turn, the current player will
  roll a pair of dice and accumulates points. The goal is to reach to 100 or more points before your
  opponent does. (For the testing purposes use 30 instead of 100 points) If, on any turn, the player
  rolls a 1, all the points accumulated for that round are forfeited and the control of the dice
  moves to the other player. If the player rolls two 1s in one turn, the player loses all the points
  accumulated thus far are forfeited and the control moves to the other player. The player may
  voluntarily turn over the control of the dice after each roll. Therefore player must decide to roll
  again (be a pig) and risk losing points, or relinquish control of the dice, possibly allowing the
  other player to win. Computer is going to flip a coin to choose the first player "</p>
  
  <p>My problem: I got the program to output that either the computer or the player is going first based on a coin flip. However, how would I actually prompt the program to run a method of the person chosen to start first, and then how would I switch between the computer and player at the end of each turn? Btw, I know this code is incomplete, but I hope that my question makes sense. </p>
  
  <p>Code so far:</p>
  
  <pre><code>import java.util.*;
  public class NavaiPigGame
  {
     public static final int POINT = 30;
     public static final int FORFEIT_POINTS = 20;
     public static void main(String[] args)
     {
        Scanner input = new Scanner(System.in);
        Random rand = new Random();
        play(rand,input);
     }
     // desription of game
     public static void description()
     {
        System.out.println("***********************************************************************************");
        System.out.println("Write a program to play the pig game against the computer. At each turn, the current player will");
        System.out.println("roll a pair of dice and accumulates points. The goal is to reach to 100 or more points before your");
        System.out.println("opponent does. (For the testing purposes use 30 instead of 100 points) If, on any turn, the player");
        System.out.println("rolls a 1, all the points accumulated for that round are forfeited and the control of the dice");
        System.out.println("moves to the other player. If the player rolls two 1s in one turn, the player loses all the points");
        System.out.println("accumulated thus far are forfeited and the control moves to the other player. The player may");
        System.out.println("voluntarily turn over the control of the dice after each roll. Therefore player must decide to roll");
        System.out.println("again (be a pig) and risk losing points, or relinquish control of the dice, possibly allowing the");
        System.out.println("other player to win. Computer is going to flip a coin to choose the first player");
        System.out.println("***********************************************************************************");
        System.out.println("lets start the fun");
     }
     //flips a coin and decides who starts the game
     public static String flipCoin(Random rand)
     {
        int coin = rand.nextInt(2);
        String comp = "";
        switch (coin)
        {
           case 0: comp = "heads";
                   break;
           case 1: comp = "tails";   
                   break;
        }
        return comp;
     }
     public static int rollDice(Random rand)
     {
        int dice1 = rand.nextInt(6)+1;
        int dice2 = rand.nextInt(6)+1;
        System.out.println("Dice 1: " +dice1);
        System.out.println("Dice 2: " +dice2);
        return dice1+dice2;     
     }
     // select a random name of the computer via arrays
     public static String nameComputer(Random rand)
     {
        int name = rand.nextInt(10);
        String compName = "";
        switch (name)
        {
           case 0: compName = "Lisa";
                   break;
           case 1: compName = "Kathy";
                   break;
           case 2: compName = "Hali";
                   break;
           case 3: compName = "Jack";
                   break;
           case 4: compName = "Alex";
                   break;
           case 5: compName = "Max";
                   break;
           case 6: compName = "Jill";
                   break;
           case 7: compName = "James";
                   break;
           case 8: compName = "Martha";
                   break;
           case 9: compName = "Lauren";
                   break;
        }
        return compName;
     }
     public static void play(Random rand, Scanner input)
     {
        int playerScores = 0;
        int playerTotal = 0;
        int computerScores = 0;
        int computerTotal = 0;
        boolean gameOver = false
        boolean turnOver = false
        description();
        String compName = nameComputer(rand);
        System.out.println("Hi my name is " + compName);
        System.out.print("What is your name? ");
        String name = input.nextLine();
        System.out.println("Hi " + name + ", I am flipping the coin to determine who goes first");
        System.out.print("press any key to start the game. ");
       input.nextLine(); 
       String flip = flipCoin(rand);
       int turn;
       if (flip.equals("heads"))
       {
          turn = 1;
          System.out.println("You are going to start the game");
       }
       else
       {
          turn = 0;
          System.out.println(compName + " is going to start the game");
       } 
     }
  }
  </code></pre>