So I have the class "Die":
public class Die
{
private int value;
private static final int HIGHEST_DIE_VALUE = 6;
private static final int LOWEST_DIE_VALUE = 1;
public Die()
{
value = ((int)(Math.random() * 100) % HIGHEST_DIE_VALUE +
LOWEST_DIE_VALUE);
}
public int getValue()
{
return value;
}
}
now I made an object array for two players:
Die[] comp = new Die[5];
Die[] player = new Die[5];
then I initialized them using a for loop to access the constructor. I can get the values to print to the screen so I know they have been set. Now I need to sort them in ascending order, how the heck do I do that. Every way I've tried has failed horribly (bubble sort and Arrays.sort()). The basis of the program is to roll 5 dice each and put them in order, then compare to see who wins. Any help is appreciated.
public class Die
{
private int value;
private static final int HIGHEST_DIE_VALUE = 6;
private static final int LOWEST_DIE_VALUE = 1;
public Die()
{
value = ((int)(Math.random() * 100) % HIGHEST_DIE_VALUE +
LOWEST_DIE_VALUE);
}
public int getValue()
{
return value;
}
}
now I made an object array for two players:
Die[] comp = new Die[5];
Die[] player = new Die[5];
then I initialized them using a for loop to access the constructor. I can get the values to print to the screen so I know they have been set. Now I need to sort them in ascending order, how the heck do I do that. Every way I've tried has failed horribly (bubble sort and Arrays.sort()). The basis of the program is to roll 5 dice each and put them in order, then compare to see who wins. Any help is appreciated.