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

Program Specification: Write a program that allows a single Player (the user to

ID: 3819907 • Letter: P

Question

Program Specification: Write a program that allows a single Player (the user to play a simple three dice game of chance against a single Opponent (the computer) Game Description There is a single Player (human), with three dice There is a single Opponent (computer), with three dice. Each die is twelve sided, and each of its sides is labeled with a unique number from 1 to 12 When a die is rolled it stops with one of its sides facing up, we will call this the value of the die roll. A game is made up of rounds, a single round is played as such 1. The computer Opponent rolls its dice 2. The dice are displayed 3. The Player rolls their dice A. The dice are displayed 5. A determination is made as to who won the round, this determination is made via the following rules: Larger values beat smaller values, same values are a tie. A Triple is when all the dice have the same number on their top faces, the value of the Triple is this common value. A Pair is when exactly two of the dice have the same number on their top faces, the value of the pair is this common value. A Nothing is then when all the dice have a different number on their top faces. Any Triple beats any Pair Any Triple beats any Nothing. Two Triples are compared by their respective Triple values. Any Pair beats any Nothing. Two Pairs are first compared by their respective Pair values, and then by their respective common die values. non Two Nothings always tie. 6. The result of the round (with respect to the Player) is announced. 7. The result of the round (with respect to the Player) is tallied, by increasing the number of player wins, ties, or loses by one The player is asked if they wish to play another round.

Explanation / Answer

import java.util.Random;

public class Die
{
      private int faceValue;
      private final int MAX=6;

      public Die()
      {
       faceValue = 1;
      }

      public void roll()
      {
       faceValue = (int)(Math.random() * MAX) +1;
      }

      public void setFaceValue(int value)
      {
      faceValue=value;
      }

      public int getFaceValue()
      {
       return faceValue;
      }

      public String toString()
      {
       String result = "You rolled a " + faceValue;

       return result;
      }

}

public class RollingDice
{
   public static void main (String[] args )
   {
       Die d1, d2 ;
       int sum ;

       d1 = new Die() ;
       d2 = new Die() ;

       d1.roll() ;
       d2.roll() ;

       System.out.println ( " Die One: " + d1 + " , Die Two: " + d2 ) ;

       sum = d1.getFaceValue() + d2.getFaceValue();
       System.out.println ( " Sum: " + sum ) ;

   }
}

public class PairOfDice
{
   private Die d1, d2;
   private int value1, value2, total;

   public PairOfDice ()
   {
      d1 = new Die();
      d2 = new Die();
      value1 = 1;
      value2 = 1;
      total = value1 + value2;
   }
   public void roll ()
   {
       d1.roll();
       d2.roll();
   }

   public int getDiceSum ()
   {
       total = getDie1() + getDie2();
      return total;
   }

   public int getDie1 ()
   {
      return value1;
   }

   public int getDie2 ()
   {
      return value2;
   }
  
   public void setDie1 (int value)
   {
       d1.setFaceValue(value);
   }

   public void setDie2(int value)
   {
       d2.setFaceValue(value);
   }
  
   public String toString()
   {
   String result = "You rolled a " + total;

   return result;
   }
  
}

import java.util.Scanner;

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

System.out.println("______________________________________");
System.out.println("/          Rules of the Game         /");
System.out.println("/          -----------------         /");
System.out.println("/ 1)It's you vs computer.           /");
System.out.println("/ 2)You play by rolling the dice.   /");
System.out.println("/ 3)The first player to reach 100   /");
System.out.println("/     points wins.                   /");
System.out.println("/ 4)When a player rolls a 1         /");
System.out.println("/     the turn is over.              /");
System.out.println("/ 5)The computer's turn is over     /");
System.out.println("/    when turn total reach 20 points /");
System.out.println("/    in a single turn.               /");
System.out.println("______________________________________");

PairOfDice d1 = new PairOfDice();

int turnTotal = 0;
int computerTotal = 0;
int playerTotal = 0;
int turnOver = 1;
int winner = 100;

Scanner in = new Scanner( System.in );
String answer;


do{
   if (playerTotal <= winner && computerTotal <= winner)
   {
       System.out.println("Your turn.");


       do
       {
       System.out.println("Type 'y' if ready and 'n' to end turn.");
       answer = in.next();

       if (answer.equalsIgnoreCase("y") && playerTotal <= winner && computerTotal <= winner)
       {
           d1.roll();
           d1.getDie1();
           d1.getDie2();
           d1.toString();
           System.out.println(d1);


           if (d1.getDie1() == turnOver || d1.getDie2() == turnOver){
               System.out.println("You rolled a 1. Your turn is over.");
               System.out.println("Please type 'done' when you are ready to turn the dice over to the Computer.");
               answer = in.next();
           }
           else
           {
               turnTotal = turnTotal + d1.getDiceSum();
               playerTotal = playerTotal + d1.getDiceSum();
               System.out.println("Your Turn Total: " + turnTotal);
               System.out.println("Your Grand Total: " + playerTotal);
           }
       }
       }

       while (answer.equalsIgnoreCase("y") && playerTotal <= winner && computerTotal <= winner);
       turnTotal = 0;
       System.out.println();
       System.out.println("Your Grand Total is: " + playerTotal);
       System.out.println("The Computer's Grand Total is: " + computerTotal);
       System.out.println();


       int endComputerTurn = 20;
       turnOver = 1;
       int answercomp = 1;

       do
       {
           if (turnTotal <= endComputerTurn && answercomp == 1 && playerTotal <= winner && computerTotal <= winner)
           {
               d1.roll();
               d1.getDie1();
               d1.getDie2();
               d1.toString();
               System.out.println(d1);
                       if (d1.getDie1() == turnOver || d1.getDie2() == turnOver)
                       {
                           System.out.println("The Computer rolled a 1. Their turn is over.");
                           answercomp = 0;
                       }

                       else
                       {
                           turnTotal = turnTotal + d1.getDiceSum();
                           computerTotal = computerTotal + d1.getDiceSum();
                           System.out.println("The Computer's Turn Total is: " + turnTotal);
                           System.out.println("The Computer's Grand Total is: " + computerTotal);
                       }
           }
       }

       while (turnTotal <= endComputerTurn && answercomp == 1 && playerTotal <= winner && computerTotal <= winner);
       turnTotal = 0;

       if (playerTotal <= winner || computerTotal <= winner)
       {
           System.out.println();
           System.out.println("The Computer's Grand Total is: " + computerTotal);
           System.out.println("Your Grand Total is: " + playerTotal);
           System.out.println();
       }

       else
       {
       System.out.println();
       System.out.println();
       }
   }
}

while(playerTotal <= winner && computerTotal <= winner);


if (playerTotal >= winner)
   System.out.println("You win!");
else
   System.out.println("You lose ): ");

}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote