From e2a21b56e9d7e81e7c9540b01ab9a88763fc8d80 Mon Sep 17 00:00:00 2001 From: Artyom_Yashin Date: Fri, 4 Oct 2024 13:50:29 +0400 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B=20=D0=B2=20=C2=AB?= =?UTF-8?q?/=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code.dart | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 code.dart diff --git a/code.dart b/code.dart new file mode 100644 index 0000000..0f2a1c6 --- /dev/null +++ b/code.dart @@ -0,0 +1,95 @@ +// Classes + +// Methods + +// Enums + +// Loops + +// Generics (можно использовать List<>) + +// Anonymous functions + +// Future + +// extension + + + +void main () async { + WorkScedule workScedule = WorkScedule(); + workScedule.push(new Worker('Слава', workDay: WeekDay.Wednesday, salary_per_day: 1500)); + workScedule.push(new Worker('Артём', workDay: WeekDay.Monday, salary_per_day: 2000)); + workScedule.push(new Worker('Лера', workDay: WeekDay.Tuesday, salary_per_day: 2500)); + workScedule.push(new Worker('Саша', workDay: WeekDay.Thursday)); + + for (var worker in await workScedule.getWorkersAsync()) + print('${worker.name} работает в ${worker.workDay.name} и получвет в месяц ${worker.fullSalary(worker.salary_per_day)}'); +} + +class Worker { + final String name; + final WeekDay workDay; + final int salary_per_day; + + Worker(this.name, { this.workDay = WeekDay.Monday, this.salary_per_day = 1000 }); + + final fullSalary = (salary_per_day) => salary_per_day*4+7700; +} + +class WorkScedule{ + List _workers = []; + + void push(Worker worker){ + _workers.add(worker); + } + + Future> getWorkersAsync() async { + await Future.delayed(Duration(seconds: 5)); + _workers.sort((a, b) => a.workDay.order.compareTo(b.workDay.order)); + return _workers; + } + +} + +enum WeekDay { + Monday, + Tuesday, + Wednesday, + Thursday, + Friday, + Saturday, + Sunday +} + +extension WeekDayX on WeekDay{ + String get name { + switch (this) { + case WeekDay.Monday: + return 'Понедельник'; + case WeekDay.Tuesday: + return 'Вторник'; + case WeekDay.Wednesday: + return 'Среда'; + case WeekDay.Thursday: + return 'Четверг'; + case WeekDay.Friday: + return 'Пятница'; + case WeekDay.Saturday: + return 'Суббота'; + case WeekDay.Sunday: + return 'Воскресенье'; + } + } + + int get order { + switch (this) { + case WeekDay.Monday: + return 1; + case WeekDay.Tuesday: + return 2; + case WeekDay.Wednesday: + return 3; + case WeekDay.Thursday: + return 4; + case WeekDay.Friday: + return 5; + case WeekDay.Saturday: + return 6; + case WeekDay.Sunday: + return 7; + } + } +} \ No newline at end of file