Index: src/tests/site/code/die.dart |
diff --git a/src/tests/site/code/die.dart b/src/tests/site/code/die.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0e71d2b186419375869d1eb92c86aa887191071c |
--- /dev/null |
+++ b/src/tests/site/code/die.dart |
@@ -0,0 +1,23 @@ |
+import 'dart:math' show Random; // Import a class from a library. |
+ |
+void main() { // This is where the app starts executing. |
Kathy Walrath
2013/11/23 00:46:27
Ew. > 80 characters. Oh well.
|
+ print(new Die(n: 12).roll()); // Print a new object's value. Chain method calls. |
+} |
+ |
+class Die { // Define a class. |
+ static Random shaker = new Random(); // Define a class variable. |
+ int sides, value; // Define instance variables. |
+ |
+ String toString() => '$value'; // Define a method using shorthand syntax. |
+ |
+ Die({int n: 6}) { // Define a constructor. |
+ if (4 <= n && n <= 20) { |
+ sides = n; |
+ } else { |
+ throw new ArgumentError(/* */); // Support for errors and exceptions. |
+ } |
+ } |
+ int roll() { // Define an instance method. |
+ return value = shaker.nextInt(sides); // Get a random number. |
+ } |
+} |