#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    1
    Rep Power
    0

    Programming with Objects- Program help


    My program is to have 2 players roll a set of dice for a maximum of 3 times. The object of the game is to have the highest total when the two die rolled are added together. The player has the option to keep the value of 1 dice, both dice or no dice. If they choose to keep the value of both dice, their turn is over and the total of the 2 die is what they keep. If they choose to keep the value of 1 dice, then they can roll the other dice 2 more times until they chose to keep the number. I have a main program, a player class which holds the value of the dice and the pairOfDice where the value of the dice is assigned as well as the total of the two die.

    When compiling the program, I get 3 specific errors:

    (1) Error: F:\COMPSCI 12\Dice game\rolldicegame.java:22: ')' expected
    (2) Error: F:\COMPSCI 12\Dice game\rolldicegame.java:22: not a statement
    (3) Error: F:\COMPSCI 12\Dice game\rolldicegame.java:22: ';' expected

    all pertaining to this line:

    Code:
     System.out.println ("First pair is " + die.get1() + " and " + die.get2() " and the total is: " + die.total());
    Why is this error showing up? and what does it mean?

    FULL CODE

    Main Program
    Code:
    import java.io.*;
    import java.lang.*;
    import java.util.*;
    
    public class rolldicegame
    {
      public static void main (String[] args) throws IOException
      {
       BufferedReader myInput = new BufferedReader (new InputStreamReader (System.in));
       
        die = new pairOfDice();
      
        
        int total = 0;
        int counter = 0;
        
        playerclass user;
        user = new playerclass();
        
        do {
          die.rollDice();
          System.out.println ("First pair is " + die.get1() + " and " + die.get2() " and the total is: " + die.total());
          
          System.out.println("Do you wish to hold the value you rolled? (1 - first die, 2 - second die, 3 - no dice 0 - both dice)");
          String inputA = myInput.readLine();
          int input = Integer.parseInt(inputA);
          
          if(input == 1){
            user.sethold1();
            user.sethold1(die.get1());
          }
          if(input == 2){
            user.sethold2();
              playerclass.sethold2(die.get2());
          }
          if(input ==3){
            break;
          }
          if(input == 0){
            user.sethold1();
            playerclass.sethold1(die.get1());
            user.sethold2();
              playerclass.sethold2(die.get2());
            
          }
          
          
          counter++;
        }
        while (die.getTotal() != 3);
      }
    }
    pairOfDice class
    Code:
    import java.io.*;
    public class pairOfDice
    {
    
      private int die1;
      private int die2;
      private int turn = 0;
      
       public pairOfDice(){
        rollDice();
      }
    
      public void rollDice(){
        die1 = (int)(Math.random()*6) + 1;
        die2 = (int)(Math.random()*6) + 1;   
        turn = turn + 1;
      }
      public void set1(int die1a, int die1){
        die1 = die1a;
      }
      
      public void set2(int die2a, int die2){
        die2 =die2a;
      }
      
      public void setTurns( int turn){
        turn = 0;
      }
      public int getTurns(int turn){
        return turn;
      }
      
      public int get1(){
        return die1;
      }
      public int get2(){
        return die2;
      }
    
      public int total(){
        return(die1 + die2);
      }
      
    }

    player class


    Code:
    import java.io.*;
    
    public class playerclass
    {
    
      int hold1 = 0;
      int hold2 = 0;
      
      public playerclass()
      {
      }
    
      
      public void sethold1(int val1){
        hold1 = val1;
      }
      
      public void sethold2(int val2){
        hold2 = val2;
      }
      
      public int getdice1(){
        return hold1;
      }
      public int getdice2(){
        return hold2;
      }
    }
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,713
    Rep Power
    348
    Make sure all of the Strings are connected by the + operator.

IMN logo majestic logo threadwatch logo seochat tools logo