-3

The Dice Class

package com.company;

import java.util.Random;

public class Die
{
     private int sides;
     private int result;
     public int roll()
{
    Random randint = new Random();
    return randint.nextInt(sides) + 1;

}
public int getSides()
{
    return sides;
}
public void setSides(int num_sides)
{
    sides = num_sides;

}
/**
 @param d Name of Dice
 */
public static void rollDie(Die d)
{
    System.out.println(d.roll());
}

}

The Game Class

package com.company;
import javax.swing.JOptionPane;


public class Game
{
public String dealerRoll()
{
  JOptionPane.showMessageDialog(null, "I will roll the dice now.");
  String choice = JOptionPane.showInputDialog("Even or odd?");
  return choice;
}
}

Main Class

package com.company;

public class Main {

public static void main(String[] args)
{
    Die Dice = new Die();
    dealerRoll();


}
}

IntelliJ is recognizing the Die in the main class, but not the dealerRoll. Can someone please tell me what I've done wrong? Im new to StackOverFlow sorry about the messed up formatting. I just learned classes in java but it works sometimes and sometimes it dosent. So please tell me whats wrong with the game class and the die class

Slava Vedenin
  • 49,939
  • 13
  • 36
  • 57
  • Welcome to Stack Overflow! Please read [How do I ask a good question?](http://stackoverflow.com/help/how-to-ask) before attempting to ask more questions. A kitten dies every time you post malformatted code that ignores idiomatic style guides. –  Jun 28 '17 at 19:53

1 Answers1

1

dealerRoll is inside Game, hence you need a reference to a game object like this:

Game game = new Game();
game.dealerRoll();

Also, please note that variable names starting with capital letters are bad practice (only classes start with capital letters), so please rename Die Dice to Die dice or to Die die

techfly
  • 1,545
  • 3
  • 23
  • 26