-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiceRollingProgram.java
More file actions
72 lines (69 loc) · 2.12 KB
/
diceRollingProgram.java
File metadata and controls
72 lines (69 loc) · 2.12 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
63
64
65
66
67
68
69
70
71
72
import java.util.Random;
import java.util.Scanner;
public class diceRollingProgram {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Random random = new Random();
int numberOfDice;
int totalOfRoll=0;
System.out.print("How many dice you wanna roll? -> ");
numberOfDice = scanner.nextInt();
if(numberOfDice<=0){
System.out.println("Enter a valid positive request...");
}
System.out.printf("Rolling %d dice...\n", numberOfDice);
for(int i=1; i<=numberOfDice; i++){
int roll = random.nextInt(1,7);
System.out.println("You rolled " + roll);
printDie(roll);
totalOfRoll += roll;
}
System.out.println("Total of all rolls: " + totalOfRoll);
}
static void printDie(int roll){
String dice1 = """
+-------+
| |
| o |
| |
+-------+""";
String dice2 = """
+-------+
| o |
| |
| o |
+-------+""";
String dice3 = """
+-------+
| o |
| o |
| o |
+-------+""";
String dice4 = """
+-------+
| o o |
| |
| o o |
+-------+""";
String dice5 = """
+-------+
| o o |
| o |
| o o |
+-------+""";
String dice6 = """
+-------+
| o o |
| o o |
| o o |
+-------+""";
switch(roll){
case 1-> System.out.println(dice1);
case 2-> System.out.println(dice2);
case 3-> System.out.println(dice3);
case 4-> System.out.println(dice4);
case 5 -> System.out.println(dice5);
case 6 -> System.out.println(dice6);
}
}
}