-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDice.java
More file actions
57 lines (34 loc) · 1.13 KB
/
Dice.java
File metadata and controls
57 lines (34 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*Veronica Pimenova
Period 6
This will represent the Dice class, with rolling and rerolling dice.*/
public class Dice{
//instance variable
private int[] diceValues;
//constructor
public Dice(int numDice){
diceValues = new int[numDice];
}
//This method will roll the dice and print their current values
public void rollDice()
{
for(int i = 0; i < diceValues.length; i++){
diceValues[i] = (int)(Math.random()*6+1);
}
}
//This method will print the current dice.
public void print(){
//print the rerolled dice
System.out.println("\n\t\tThe dice have been rolled: ");
for(int i = 0; i < diceValues.length; i++)
System.out.println("\tDice "+(i+1)+": "+diceValues[i]);
}
/*This method will return the dice values
@return int[] diceValues*/
public int[] getDiceValues(){
return diceValues;
}
/*This method will reroll one specific dice*/
public void rerollDice(int die){
diceValues[die] = (int)(Math.random()*6+7);
}
}