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

    Join Date
    Sep 2013
    Posts
    5
    Rep Power
    0

    Objects classes and methods program trouble


    My program is meant for two players. Each player gets to roll the dice three times each, where they can keep numbers that they roll each roll. If they keep one number from the first roll, they can continue to roll two more times until they choose to keep the number. the two dice are added together and the player with the highest sum wins. I have a player class (in charge of keeping the dice values), the pairOfdice class where the dice are rooled and the sum is determined, and the main game. When I run the program, I receive these errors from the diceGame class. I would like to know why these errors are appearing. My code is not complete yet.

    - getHoldA() in playerGame cannot be applied to (int)
    - getHoldB() in playerGame cannot be applied to (int)

    Code:
    import java.io.*;
    import java.lang.*;
    import java.util.*;
    
      
      
    public class diceGame
    {
       public static void main(String[] args) {
    
      pairOfDice dice;
      
      dice = new pairOfDice();
      
      playerGame player;
      
      player = new playerGame();
      
      int rollCount = 0;
      
     int holdA = 0, holdB = 0;
      do {
               dice.roll();    // Roll the first pair of dice.
                System.out.println("Dice 1: " + dice.getDiceA() + "\n" + "Dice 2: " + dice.getDiceB() + "\n" + "The total is: " + dice.getTotal());
        System.out.println("Do you want to hold the fist dice with a value of " + dice.getDiceA());
        if (holdA == 1){
          player.getHoldA();
              player.getHoldA(dice.getDiceA());
              System.out.println("Value of dice A is held");
        }
        System.out.println("Do you want to hold the second dice with a value of " + dice.getDiceB());
          if (holdB == 1){
                player.getHoldB(dice.getDiceB());
                System.out.println("Value of dice B is held");
        }
        
               rollCount++;
                }
      while (dice.getTurns() <= 3);
      }
    }
    This is the player class
    Code:
    import java.io.*;
    
    public class playerGame
    {
         private int holdA = 0, holdB = 0;
         
         //constructor
         public playerGame(){
         }
         
          public void setHoldA (int valA){
             holdA = valA;
           }
         public void setHoldB (int valB){
         holdB = valB;
         }
         public void setPlayer(int player){
           player = player + 1;
         }
         
         public int getHoldA () {
           return holdA;
         }
         public int getHoldB () {
           return holdB;
         }    
        
           }
    And this is the pairOfDice class

    Code:
    import java.io.*;
    
    public class pairOfDice
    {
      
      private int diceA = 0, diceB = 0, turns = 0;
      
      public pairOfDice() {//constructor
        roll();  
      }
      public void roll(){
        diceA = (int)(Math.random()*6) + 1;
        diceB = (int)(Math.random()*6) + 1;
        turns = turns +1;
      }
      
      public void setDice(int newDiceA, int diceA) {
        diceA = newDiceA;
      }
      public void setDiceB(int newDiceB, int diceB) {
        diceB = newDiceB;
      }
      public void setTurns(int turns) {
        turns = 0;
      }
      
      public int getDiceA() {
        return diceA;
      }
      public int getDiceB() {
        return diceB;
      }
      public int getTotal() {
        return (diceA + diceB);
      }
      public int getTurns() {
        return turns;
      }
    }
  2. #2
  3. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Feb 2004
    Location
    Mobile, Alabama
    Posts
    4,022
    Rep Power
    1285
    Your methods getHoldA() and getHoldB() don't accept parameters.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    5
    Rep Power
    0
    Thanks, I've changed it and it works now. Is it possible to ask another quick question? I was adding things to my code and when compiled it says that "myInput" can't be found. Why is this?

    Code:
    import java.io.*;
    import java.lang.*;
    import java.util.*;
    
    
    
    public class diceGame
    {
      public static void main(String[] args) throws IOException {
        
        pairOfDice dice;
        
        dice = new pairOfDice();
        
        playerGame player;
        
        player = new playerGame();
        
        int rollCount = 0;
        
        int holdB = 0;
        do {
          dice.roll();    // Roll the first pair of dice.
          System.out.println("Dice 1: " + dice.getDiceA() + "\n" + "Dice 2: " + dice.getDiceB() + "\n" + "The total is: " + dice.getTotal());
          System.out.println("Do you want to hold the value of the dice? Press 0 to hold none/ 1 to hold die 1/ 2 to hold die 2/ 3 to hold both");
          String hold = myInput.readLine();
          int holdA = Integer.parseInt(hold);
          if (holdA == 0){
          }
          if (holdA == 1){
            player.getHoldA();
            player.setHoldA(dice.getDiceA());
            System.out.println("Value of dice A is held");
          }
          if (holdA == 2){
            player.setHoldB(dice.getDiceB());
            System.out.println("Value of dice B is held");
          }
          if (holdA == 3){
            player.setHoldA(dice.getDiceA());
            System.out.println("Value of dice A is held");
            player.setHoldB(dice.getDiceB());
            System.out.println("Value of dice B is held");
            break;
          }
          rollCount++;
        }
        while (dice.getTurns() <= 3);
      }
    }
  6. #4
  7. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Feb 2004
    Location
    Mobile, Alabama
    Posts
    4,022
    Rep Power
    1285
    You haven't defined it.

    That is, you haven't declared myInput to be anything.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    5
    Rep Power
    0
    Originally Posted by bullet
    You haven't defined it.

    That is, you haven't declared myInput to be anything.
    thanks, I forgot to add that

IMN logo majestic logo threadwatch logo seochat tools logo