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>
2929import 'dart:math' show Random;
3030
3131void main() {
32- print(new Die(n: 12).roll());
32+ print(Die(n: 12).roll());
3333}
3434
3535// Define a class.
3636class Die {
3737 // Define a class variable.
38- static Random shaker = new Random();
38+ static final Random shaker = Random();
3939
4040 // 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;
4543
4644 // 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) {
5147 // Support for errors and exceptions.
52- throw new ArgumentError(/* */);
48+ throw ArgumentError(/* */);
5349 }
5450 }
5551
52+ // Define a method using shorthand syntax.
53+ @override
54+ String toString() => '$lastRoll';
55+
5656 // Define an instance method.
5757 int roll() {
58- return value = shaker.nextInt(sides) + 1;
58+ return lastRoll = shaker.nextInt(sides) + 1;
5959 }
6060}
6161</ textarea >
You can’t perform that action at this time.
0 commit comments