-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoll01Dice.java
More file actions
62 lines (53 loc) · 1.91 KB
/
Copy pathRoll01Dice.java
File metadata and controls
62 lines (53 loc) · 1.91 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
58
59
60
61
62
/**
* Number fun project
*
*
* @author Ainsley Pyle
*
* Created at : 2023-09-25 12:02:26
* Last modified : 2023-09-25 13:11:59
*/
import java.util.Random;
public class Roll01Dice {
//Method for rolling the dice using a random number generator
private static void rollDice(int[] dice){
Random randomEngine = new Random();
for (int i = 0; i < dice.length; ++i){
dice[i]=randomEngine.nextInt(6)+1;
}
}
//Method for raising dice 0 to power of dice 1
private static double raiseToPower(int[] dice){
double rtn;
rtn = Math.pow((double)dice[0], (double)dice[1]);
return rtn;
}
//Method for finding the square root of both values
private static double[] squareRoot (int[] dice){
double[] roots = new double[dice.length];
for(int i=0; i < dice.length; i++) {
roots[i] = Math.sqrt((double)dice[i]);
}
return roots;
}
//Method for finding the ceiling of the roots
private static double[] rootCeiling(double[] roots){
double[] ceilings = new double[roots.length];
for (int i=0; i < roots.length; i++){
ceilings[i] = Math.ceil(roots[i]);
}
return ceilings;
}
//Main
public static void main (String [] args){
int[] dice = new int[2];
rollDice(dice);
System.out.println ("The dice are "+ dice[0]+ " and "+dice[1]+".");
double powValue = raiseToPower(dice);
double[] roots = squareRoot(dice);
double[] ceilings = rootCeiling(roots);
System.out.println("The value of d1 raised to the power of d2 is "+ powValue+".");
System.out.println("The square roots are " +roots[0]+" for dice 1 and "+roots[1]+" for dice 2.");
System.out.println("The ceilings of the roots are "+ ceilings[0]+" and "+ceilings[1]+".");
}
}