OLD | NEW |
1 | 1 |
2 #library("pets"); | 2 #library("pets"); |
3 | 3 |
| 4 #import('dart:math'); |
| 5 |
4 final num MAX_CATS = 10; | 6 final num MAX_CATS = 10; |
5 | 7 |
6 final SPARKY = const Cat("Sparky"); | 8 final SPARKY = const Cat("Sparky"); |
7 | 9 |
8 interface Animal { | 10 interface Animal { |
9 bool livesWith(Animal other); | 11 bool livesWith(Animal other); |
10 void performAction(); | 12 void performAction(); |
11 } | 13 } |
12 | 14 |
13 class Cat implements Animal { | 15 class Cat implements Animal { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 47 |
46 String name; | 48 String name; |
47 | 49 |
48 bool collar; | 50 bool collar; |
49 | 51 |
50 int fleaCount; | 52 int fleaCount; |
51 | 53 |
52 Date bornOn; | 54 Date bornOn; |
53 | 55 |
54 Dog(this.name) { | 56 Dog(this.name) { |
55 fleaCount = (Math.random() * 10.0).round().toInt(); | 57 var rand = new Random(); |
| 58 fleaCount = rand.nextInt(10); |
56 bornOn = new Date.now(); | 59 bornOn = new Date.now(); |
57 } | 60 } |
58 | 61 |
59 Dog.withFleas(this.name, this.fleaCount) { | 62 Dog.withFleas(this.name, this.fleaCount) { |
60 bornOn = new Date.now(); | 63 bornOn = new Date.now(); |
61 } | 64 } |
62 | 65 |
63 bool livesWith(Animal other) => true; | 66 bool livesWith(Animal other) => true; |
64 | 67 |
65 void performAction() { | 68 void performAction() { |
(...skipping 25 matching lines...) Expand all Loading... |
91 } | 94 } |
92 | 95 |
93 return map; | 96 return map; |
94 } | 97 } |
95 | 98 |
96 void testInfinity() { | 99 void testInfinity() { |
97 var infTest = 1 / 0; | 100 var infTest = 1 / 0; |
98 | 101 |
99 print(infTest); // Infinity | 102 print(infTest); // Infinity |
100 } | 103 } |
OLD | NEW |