From 53faa33ac69598b7495e160824b58ebb8d70fe97 Mon Sep 17 00:00:00 2001 From: Parker Lougheed Date: Sun, 10 Sep 2023 10:36:12 -0500 Subject: [PATCH] [dart mdoe] Fix code example to compile and run with modern Dart versions --- mode/dart/index.html | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/mode/dart/index.html b/mode/dart/index.html index 88b8936dec..ee6128c1f7 100644 --- a/mode/dart/index.html +++ b/mode/dart/index.html @@ -29,33 +29,33 @@

Dart mode

import 'dart:math' show Random; void main() { - print(new Die(n: 12).roll()); + print(Die(n: 12).roll()); } // Define a class. class Die { // Define a class variable. - static Random shaker = new Random(); + static final Random shaker = Random(); // Define instance variables. - int sides, value; - - // Define a method using shorthand syntax. - String toString() => '$value'; + final int sides; + int? lastRoll; // Define a constructor. - Die({int n: 6}) { - if (4 <= n && n <= 20) { - sides = n; - } else { + Die({int n = 6}) : sides = n { + if (4 > n || n > 20) { // Support for errors and exceptions. - throw new ArgumentError(/* */); + throw ArgumentError(/* */); } } + // Define a method using shorthand syntax. + @override + String toString() => '$lastRoll'; + // Define an instance method. int roll() { - return value = shaker.nextInt(sides) + 1; + return lastRoll = shaker.nextInt(sides) + 1; } }