File tree Expand file tree Collapse file tree 1 file changed +12
-12
lines changed Expand file tree Collapse file tree 1 file changed +12
-12
lines changed Original file line number Diff line number Diff line change @@ -29,33 +29,33 @@ <h2>Dart mode</h2>
29
29
import 'dart:math' show Random;
30
30
31
31
void main() {
32
- print(new Die(n: 12).roll());
32
+ print(Die(n: 12).roll());
33
33
}
34
34
35
35
// Define a class.
36
36
class Die {
37
37
// Define a class variable.
38
- static Random shaker = new Random();
38
+ static final Random shaker = Random();
39
39
40
40
// Define instance variables.
41
- int sides, value;
42
-
43
- // Define a method using shorthand syntax.
44
- String toString() => '$value';
41
+ final int sides;
42
+ int? lastRoll;
45
43
46
44
// Define a constructor.
47
- Die({int n: 6}) {
48
- if (4 < = n && n < = 20) {
49
- sides = n;
50
- } else {
45
+ Die({int n = 6}) : sides = n {
46
+ if (4 > n || n > 20) {
51
47
// Support for errors and exceptions.
52
- throw new ArgumentError(/* */);
48
+ throw ArgumentError(/* */);
53
49
}
54
50
}
55
51
52
+ // Define a method using shorthand syntax.
53
+ @override
54
+ String toString() => '$lastRoll';
55
+
56
56
// Define an instance method.
57
57
int roll() {
58
- return value = shaker.nextInt(sides) + 1;
58
+ return lastRoll = shaker.nextInt(sides) + 1;
59
59
}
60
60
}
61
61
</ textarea >
You can’t perform that action at this time.
0 commit comments