Skip to content

Commit f4cd70c

Browse files
committed
prefinals
1 parent be0cb11 commit f4cd70c

File tree

7,827 files changed

+2023805
-69174
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

7,827 files changed

+2023805
-69174
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
library bank_terminal;
2+
3+
import 'dart:convert';
4+
5+
part 'model/bank_account.dart';
6+
part 'model/person.dart';
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
part of bank_terminal;
2+
3+
class BankAccount {
4+
String _number;
5+
Person owner;
6+
double _balance;
7+
int _pin_code;
8+
final DateTime date_created;
9+
DateTime date_modified;
10+
static const double INTEREST = 5.0;
11+
12+
String get number => _number;
13+
set number(value) {
14+
if (value == null || value.isEmpty) return;
15+
// test the format:
16+
RegExp exp = new RegExp(r"[0-9]{3}-[0-9]{7}-[0-9]{2}");
17+
if (exp.hasMatch(value)) _number = value;
18+
}
19+
20+
double get balance => _balance;
21+
set balance(value) {
22+
if (value >= 0) _balance = value;
23+
}
24+
25+
int get pin_code => _pin_code;
26+
set pin_code(value) {
27+
if (value >= 1 && value <= 999999) _pin_code = value;
28+
}
29+
30+
// constructors:
31+
BankAccount(this.owner, number, balance, pin_code): date_created = new DateTime.now() {
32+
this.number = number;
33+
this.balance = balance;
34+
this.pin_code = pin_code;
35+
date_modified = date_created;
36+
}
37+
BankAccount.sameOwner(BankAccount acc): owner = acc.owner, date_created = new DateTime.now();
38+
BankAccount.sameOwnerInit(BankAccount acc): this(acc.owner, "000-0000000-00", 0.0, 0);
39+
40+
BankAccount.fromJson(Map json): date_created = DateTime.parse(json["creation_date"]) {
41+
this.number = json["number"];
42+
this.owner = new Person.fromJson(json["owner"]);
43+
this.balance = json["balance"];
44+
this.pin_code = json["pin_code"];
45+
this.date_modified = DateTime.parse(json["modified_date"]);
46+
}
47+
BankAccount.fromJsonString(String jsonString): this.fromJson(JSON.decode(jsonString));
48+
49+
// methods:
50+
deposit(double amount) {
51+
balance += amount;
52+
date_modified = new DateTime.now();
53+
}
54+
55+
withdraw(double amount) {
56+
balance += amount;
57+
date_modified = new DateTime.now();
58+
}
59+
60+
interest() {
61+
balance += balance * INTEREST/100.0;
62+
}
63+
64+
String toString() => 'Bank account from $owner with number $number'
65+
' and balance $balance';
66+
67+
String toJson() {
68+
var acc = new Map<String, Object>();
69+
acc["number"] = number;
70+
acc["owner"] = owner.toJson();
71+
acc["balance"] = balance;
72+
acc["pin_code"] = pin_code;
73+
acc["creation_date"] = date_created.toString();
74+
acc["modified_date"] = date_modified.toString();
75+
var accs = JSON.encode(acc); // use only once for the root object (here a bank account)
76+
return accs;
77+
}
78+
}
79+
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
part of bank_terminal;
2+
3+
class Person {
4+
// Person properties:
5+
String _name, address, _email, _gender;
6+
DateTime _date_birth;
7+
8+
String get name => _name;
9+
set name(value) {
10+
if (value != null && !value.isEmpty) _name = value;
11+
}
12+
13+
String get email => _email;
14+
set email(value) {
15+
if (value != null && !value.isEmpty) _email = value;
16+
}
17+
18+
String get gender => _gender;
19+
set gender(value) {
20+
if (value == 'M' || value == 'F') _gender = value;
21+
}
22+
23+
DateTime get date_birth => _date_birth;
24+
set date_birth(value) {
25+
DateTime now = new DateTime.now();
26+
if (value.isBefore(now)) _date_birth = value;
27+
}
28+
29+
// constructors:
30+
Person(name, this.address, email, gender, date_birth) {
31+
this.name = name;
32+
this.email = email;
33+
this.gender = gender;
34+
this.date_birth = date_birth;
35+
}
36+
37+
Person.fromJson(Map json) {
38+
this.name = json["name"];
39+
this.address = json["address"];
40+
this.email = json["email"];
41+
this.gender = json["gender"];
42+
this.date_birth = DateTime.parse(json["birthdate"]);
43+
}
44+
45+
// methods:
46+
String toString() => 'Person: $name, $gender';
47+
48+
Map<String, Object> toJson() {
49+
Map<String, Object> per = new Map<String, Object>();
50+
per["name"] = name;
51+
per["address"] = address;
52+
per["email"] = email;
53+
per["gender"] = gender;
54+
per["birthdate"] = date_birth.toString();
55+
return per;
56+
}
57+
}
58+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
(function() {
6+
// Bootstrap support for Dart scripts on the page as this script.
7+
if (navigator.userAgent.indexOf('(Dart)') === -1) {
8+
// TODO:
9+
// - Support in-browser compilation.
10+
// - Handle inline Dart scripts.
11+
12+
// Fall back to compiled JS. Run through all the scripts and
13+
// replace them if they have a type that indicate that they source
14+
// in Dart code (type="application/dart").
15+
var scripts = document.getElementsByTagName("script");
16+
var length = scripts.length;
17+
for (var i = 0; i < length; ++i) {
18+
if (scripts[i].type == "application/dart") {
19+
// Remap foo.dart to foo.dart.js.
20+
if (scripts[i].src && scripts[i].src != '') {
21+
var script = document.createElement('script');
22+
script.src = scripts[i].src.replace(/\.dart(?=\?|$)/, '.dart.js');
23+
var parent = scripts[i].parentNode;
24+
// TODO(vsm): Find a solution for issue 8455 that works with more
25+
// than one script.
26+
document.currentScript = script;
27+
parent.replaceChild(script, scripts[i]);
28+
}
29+
}
30+
}
31+
}
32+
})();
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// TODO(jmesserly): remove this script after a deprecation period.
6+
if (typeof console == "object" && typeof console.warn == "function") {
7+
console.warn('<script src="packages/browser/interop.js"> is no longer ' +
8+
'needed for dart:js. See http://pub.dartlang.org/packages/browser.');
9+
}

Chapter 1/bank_terminal/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ packages:
44
browser:
55
description: browser
66
source: hosted
7-
version: "0.9.0"
7+
version: "0.10.0+2"

Chapter 1/bank_terminal/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: bank_terminal_s5
1+
name: bank_terminal
22
description: A sample web application
33
dependencies:
44
browser: any

Chapter 1/bank_terminal/web/bank_terminal_s5.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import 'dart:html';
2-
import 'package:bank_terminal_s5/bank_terminal.dart';
2+
import 'package:bank_terminal/bank_terminal.dart';
33

44
LabelElement owner, balance, error;
55
InputElement number, amount;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
library bank_terminal;
2+
3+
import 'dart:convert';
4+
5+
part 'model/bank_account.dart';
6+
part 'model/person.dart';
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
part of bank_terminal;
2+
3+
class BankAccount {
4+
String _number;
5+
Person owner;
6+
double _balance;
7+
int _pin_code;
8+
final DateTime date_created;
9+
DateTime date_modified;
10+
static const double INTEREST = 5.0;
11+
12+
String get number => _number;
13+
set number(value) {
14+
if (value == null || value.isEmpty) return;
15+
// test the format:
16+
RegExp exp = new RegExp(r"[0-9]{3}-[0-9]{7}-[0-9]{2}");
17+
if (exp.hasMatch(value)) _number = value;
18+
}
19+
20+
double get balance => _balance;
21+
set balance(value) {
22+
if (value >= 0) _balance = value;
23+
}
24+
25+
int get pin_code => _pin_code;
26+
set pin_code(value) {
27+
if (value >= 1 && value <= 999999) _pin_code = value;
28+
}
29+
30+
// constructors:
31+
BankAccount(this.owner, number, balance, pin_code): date_created = new DateTime.now() {
32+
this.number = number;
33+
this.balance = balance;
34+
this.pin_code = pin_code;
35+
date_modified = date_created;
36+
}
37+
BankAccount.sameOwner(BankAccount acc): owner = acc.owner, date_created = new DateTime.now();
38+
BankAccount.sameOwnerInit(BankAccount acc): this(acc.owner, "000-0000000-00", 0.0, 0);
39+
40+
BankAccount.fromJson(Map json): date_created = DateTime.parse(json["creation_date"]) {
41+
this.number = json["number"];
42+
this.owner = new Person.fromJson(json["owner"]);
43+
this.balance = json["balance"];
44+
this.pin_code = json["pin_code"];
45+
this.date_modified = DateTime.parse(json["modified_date"]);
46+
}
47+
BankAccount.fromJsonString(String jsonString): this.fromJson(JSON.decode(jsonString));
48+
49+
// methods:
50+
deposit(double amount) {
51+
balance += amount;
52+
date_modified = new DateTime.now();
53+
}
54+
55+
withdraw(double amount) {
56+
balance += amount;
57+
date_modified = new DateTime.now();
58+
}
59+
60+
interest() {
61+
balance += balance * INTEREST/100.0;
62+
}
63+
64+
String toString() => 'Bank account from $owner with number $number'
65+
' and balance $balance';
66+
67+
String toJson() {
68+
var acc = new Map<String, Object>();
69+
acc["number"] = number;
70+
acc["owner"] = owner.toJson();
71+
acc["balance"] = balance;
72+
acc["pin_code"] = pin_code;
73+
acc["creation_date"] = date_created.toString();
74+
acc["modified_date"] = date_modified.toString();
75+
var accs = JSON.encode(acc); // use only once for the root object (here a bank account)
76+
return accs;
77+
}
78+
}
79+
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
part of bank_terminal;
2+
3+
class Person {
4+
// Person properties:
5+
String _name, address, _email, _gender;
6+
DateTime _date_birth;
7+
8+
String get name => _name;
9+
set name(value) {
10+
if (value != null && !value.isEmpty) _name = value;
11+
}
12+
13+
String get email => _email;
14+
set email(value) {
15+
if (value != null && !value.isEmpty) _email = value;
16+
}
17+
18+
String get gender => _gender;
19+
set gender(value) {
20+
if (value == 'M' || value == 'F') _gender = value;
21+
}
22+
23+
DateTime get date_birth => _date_birth;
24+
set date_birth(value) {
25+
DateTime now = new DateTime.now();
26+
if (value.isBefore(now)) _date_birth = value;
27+
}
28+
29+
// constructors:
30+
Person(name, this.address, email, gender, date_birth) {
31+
this.name = name;
32+
this.email = email;
33+
this.gender = gender;
34+
this.date_birth = date_birth;
35+
}
36+
37+
Person.fromJson(Map json) {
38+
this.name = json["name"];
39+
this.address = json["address"];
40+
this.email = json["email"];
41+
this.gender = json["gender"];
42+
this.date_birth = DateTime.parse(json["birthdate"]);
43+
}
44+
45+
// methods:
46+
String toString() => 'Person: $name, $gender';
47+
48+
Map<String, Object> toJson() {
49+
Map<String, Object> per = new Map<String, Object>();
50+
per["name"] = name;
51+
per["address"] = address;
52+
per["email"] = email;
53+
per["gender"] = gender;
54+
per["birthdate"] = date_birth.toString();
55+
return per;
56+
}
57+
}
58+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
(function() {
6+
// Bootstrap support for Dart scripts on the page as this script.
7+
if (navigator.userAgent.indexOf('(Dart)') === -1) {
8+
// TODO:
9+
// - Support in-browser compilation.
10+
// - Handle inline Dart scripts.
11+
12+
// Fall back to compiled JS. Run through all the scripts and
13+
// replace them if they have a type that indicate that they source
14+
// in Dart code (type="application/dart").
15+
var scripts = document.getElementsByTagName("script");
16+
var length = scripts.length;
17+
for (var i = 0; i < length; ++i) {
18+
if (scripts[i].type == "application/dart") {
19+
// Remap foo.dart to foo.dart.js.
20+
if (scripts[i].src && scripts[i].src != '') {
21+
var script = document.createElement('script');
22+
script.src = scripts[i].src.replace(/\.dart(?=\?|$)/, '.dart.js');
23+
var parent = scripts[i].parentNode;
24+
// TODO(vsm): Find a solution for issue 8455 that works with more
25+
// than one script.
26+
document.currentScript = script;
27+
parent.replaceChild(script, scripts[i]);
28+
}
29+
}
30+
}
31+
}
32+
})();
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// TODO(jmesserly): remove this script after a deprecation period.
6+
if (typeof console == "object" && typeof console.warn == "function") {
7+
console.warn('<script src="packages/browser/interop.js"> is no longer ' +
8+
'needed for dart:js. See http://pub.dartlang.org/packages/browser.');
9+
}

0 commit comments

Comments
 (0)