I'm new to all programming. I'm stonewalled, and I'll show what I have.My assignment is this:
Write a Java Dice class which will simulate the rolling of one die and
display the die face.
Follow these requirements for the Dice class:
· 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 as below:
Requirements:
The Dice class should be named Dice.java.
Include comments defining the purpose of the code.
Six:
* *
* *
* *
Five:
* *
*
* *
Four:
* *
* *
Three:
*
*
*
Two:
*
*
One:
*
Here's my code:[CODE=Java]
import java.util.Rando m; // 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 arandom number.
face = randomNumbers.n extInt(6)+ 1;
face = diceRoll();
// Display results.
if (face == 1)
System.out.prin tln("One:\n *");
else if (face == 2)
System.out.prin tln("Two:\n*\n\ n *");
else if (face == 3)
System.out.prin tln("Three:\n*\ n *\n *");
else if (face == 4)
System.out.prin tln("Four:\n* *\n\n* *");
else if (face == 5)
System.out.prin tln("Five:\n* *\n *\n* *");
else if (face == 6)
System.out.prin tln("Six:\n* *\n* *\n* *");
}
public int diceRoll()
{
return diceRoll();
}
}[/CODE]
Gives me this error:
Dice.java:14: non-static method diceRoll() cannot be referenced from a static context
Write a Java Dice class which will simulate the rolling of one die and
display the die face.
Follow these requirements for the Dice class:
· 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 as below:
Requirements:
The Dice class should be named Dice.java.
Include comments defining the purpose of the code.
Six:
* *
* *
* *
Five:
* *
*
* *
Four:
* *
* *
Three:
*
*
*
Two:
*
*
One:
*
Here's my code:[CODE=Java]
import java.util.Rando m; // 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 arandom number.
face = randomNumbers.n extInt(6)+ 1;
face = diceRoll();
// Display results.
if (face == 1)
System.out.prin tln("One:\n *");
else if (face == 2)
System.out.prin tln("Two:\n*\n\ n *");
else if (face == 3)
System.out.prin tln("Three:\n*\ n *\n *");
else if (face == 4)
System.out.prin tln("Four:\n* *\n\n* *");
else if (face == 5)
System.out.prin tln("Five:\n* *\n *\n* *");
else if (face == 6)
System.out.prin tln("Six:\n* *\n* *\n* *");
}
public int diceRoll()
{
return diceRoll();
}
}[/CODE]
Gives me this error:
Dice.java:14: non-static method diceRoll() cannot be referenced from a static context
Comment