dimanche 28 mai 2017

Need Help printing five random numbers (like dice throws) for computer and player. I need to use ( randomeValue= ) statement seen in code

My code is only producing two random numbers and not five for player and computer like I need it to. Can anybody see the problem?

import java.util.Random;

public class Die{

      private static int HIGHEST_DIE_VALUE=6;
      private static int LOWEST_DIE_VALUE=1;
      private int randomValue;

    public Die(){
                randomValue = ((int)(Math.random() * 100) % HIGHEST_DIE_VALUE + LOWEST_DIE_VALUE);
        }

    private void generateRandom(){
              randomValue = ((int)(Math.random() * 100) % HIGHEST_DIE_VALUE + LOWEST_DIE_VALUE);
    }

    public int getValue(){
        return randomValue;
      }
}

public class FiveDice {

    public static void main(String[] args){

            Die computer = new Die();
            Die player = new Die();

                System.out.println("Computer five random die values:");
                System.out.println("\tDie 1 rolled a " + computer.getValue() + " value");
                System.out.println("\tDie 2 rolled a " + computer.getValue() + " value");
                System.out.println("\tDie 3 rolled a " + computer.getValue() + " value");
                System.out.println("\tDie 4 rolled a " + computer.getValue() + " value");
                System.out.println("\tDie 5 rolled a " + computer.getValue() + " value");

                System.out.println("\nPlayer five random die values");
                System.out.println("\t\tDie 1 rolled a " + player.getValue() + " value");
                System.out.println("\t\tDie 2 rolled a " + player.getValue() + " value");
                System.out.println("\t\tDie 3 rolled a " + player.getValue() + " value");
                System.out.println("\t\tDie 4 rolled a " + player.getValue() + " value");
                System.out.println("\t\tDie 5 rolled a " + player.getValue() + " value");   


        }

}

This is what the output:

Computer five random die values:
Die 1 rolled a 5 value
Die 2 rolled a 5 value
Die 3 rolled a 5 value
Die 4 rolled a 5 value
Die 5 rolled a 5 value

Player five random die values
Die 1 rolled a 4 value
Die 2 rolled a 4 value
Die 3 rolled a 4 value
Die 4 rolled a 4 value
Die 5 rolled a 4 value

I need each die for each player to be random numbers. Any help?




Aucun commentaire:

Enregistrer un commentaire