Hello - I'm a brand new student of programming and I'm needing help. I'm stonewalled. I've got an assignment that requires me to create a class named Dice that another program will use to roll dice.
The instructions are:
- The class must be named Dice
- A method named diceRoll() must be included
- A random number between 1 and 6 inclusive must be generated
- The random number value generated must be returned
- The face of the die must be displayed below: (description of display not included here - I've got that in my code, and it works right)
Here is my code thus far. It compiles/runs fine - I think it does what it's supposed to do, BUT... I don't know how to create or implement or include this method diceRoll(), which professor's program needs to make hers work. This part confuses me. I take this course online - the book is helpful, but I have had little or no communication or help otherwise. Thanks in advance for any ideas:
import java.util.Random; // Needed for random dice numbers.
public class Dice
{
public static void main (String[] args)
{
int face; // The face of the die.
// A random object for the program.
Random randomNumbers = new Random();
// Die face number is set equal to a random number.
face = randomNumbers.nextInt(6)+ 1;
// Display results.
if (face == 1)
System.out.println("One:\n\n *");
else if (face == 2)
System.out.println("Two:\n*\n\n *");
else if (face == 3)
System.out.println("Three:\n*\n *\n *");
else if (face == 4)
System.out.println("Four:\n* *\n\n* *");
else if (face == 5)
System.out.println("Five:\n* *\n *\n* *");
else if (face == 6)
System.out.println("Six:\n* *\n* *\n* *");
}
}