Last active
May 30, 2025 09:38
-
-
Save alex-stewart-sporty/d024cba4f2f0fde8f7d22211454c500e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Random; | |
public class Dice { | |
private Integer faces; | |
public Dice(int faces) { | |
this.faces = faces; | |
} | |
public void setFaces(int faces) { | |
this.faces = faces; | |
} | |
public Integer roll() { | |
Random var = new Random(); | |
return var.nextInt(faces); | |
} | |
public Integer rollingSummingX(int x) { | |
int r = 0; | |
for (int i = 0; i < x; i++) { | |
r = r + roll(); | |
} | |
return r; | |
} | |
public Integer[] rollingX(Integer x) { | |
Integer[] results = new Integer[x]; | |
for (int i = 0; i < x; i++) { | |
results[i] = roll(); | |
} | |
return results; | |
} | |
public String flipCoin() { | |
if (new Random().nextInt(2) == 0) { | |
return "heads"; | |
} else { | |
return "tails"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment