I am trying to create a dice program and I am need the output to be a string of 'One', 'Two', 'Three', etc. It is currently printing an output of 0 but that is because my OutputDice method is incorrect. When I take it out it passes the arguments as integers, but I need them as strings. How do I do that?
My code is as follows:
import java.util.Random;
public class Dice {
private int Value;
public void setValue(int diceValue)
{
Value = diceValue;
}
public int getValue()
{
return Value;
}
public void roll()
{
Random rand = new Random();
Value = rand.nextInt(6) + 1;
}
public void OutputDice()
{
switch (Value)
{
case 1:
System.out.println("One");
case 2:
System.out.println("Two");
case 3:
System.out.println("Three");
case 4:
System.out.println("Four");
case 5:
System.out.println("Five");
case 6:
System.out.println("Six");
}
}
}
and
public class DiceRoll {
public static void main(String[]args) {
Dice firstDie = new Dice();
Dice secondDie = new Dice();
firstDie.OutputDice();
secondDie.OutputDice();
System.out.println("Dice 1: "+ firstDie.getValue());
System.out.println("Dice 2: "+ secondDie.getValue());
}
}
roll