- The first thing that i havent been able to fix is it only rolls 1 die when its supposed to be 2.
- Second I have no idea how to do make my counter, i know its supposed to be something like playerTotal++
- Third once i get the counter i could make the if statement for it over 21 you lose. then make the comp play.
import java.util.Scanner;
public class AGameOfTwentyOne
{
public static void main(String [] args)
{
String rollDie = "y";
int playerTotal = 0;
Scanner kb = new Scanner(System.in);
Die playerDie = new Die();
Die compDie = new Die();
do
{
while(rollDie.equalsIgnoreCase("y"))
{
System.out.print("Roll the dice? (y/n) : ");
rollDie = kb.nextLine();
playerDie.roll();
playerDie.roll();
System.out.println("Your score is: "+ playerDie.getValue());
}
}while(rollDie == "y");
}
}
import java.util.Random;
public class Die
{
private final int SIDES = 6;
private int value;
Die()
{
roll();
}
public void roll()
{
Random randomValue = new Random();
value = randomValue.nextInt(SIDES) + 1;
}
public int getValue()
{
return value;
}
}

New Topic/Question
Reply



MultiQuote




|