lundi 30 mai 2022

Making a 1-6 random number class Java

for some reason when i call on this class it doesn't return me anything. class will need two instance properties, die1 and die2, which will be used to store the value of each die(1-6).

//define class variables here
Random rd = new Random();
int die1;
int die2;
//define class methods here

method requires no arguments. When called, the method will generate random numbers between 1-6 and assign them to die1 and die2. A different random number will be generated for each die. The return type should be void.

public void roll () {

this.die1 = 1 + rd.nextInt(6);
this.die2 = 1 + rd.nextInt(6);

}

method will return the sum of both die values as an integer when called. This should be a number between 2 and 12.

public int getTotal() {

int sum = die1 + die2;

return sum;

}

Getter method that returns the value of the first die.

public int getDice1(int dice1) {

this.die1 = dice1;

return this.die1;

}

Getter method that returns the value of the second die.

public int getDice2(int dice2) {

this.die2 = dice2;
return this.die2;
}

}




Aucun commentaire:

Enregistrer un commentaire