MDP_Yashin/code.dart

95 lines
2.4 KiB
Dart

// 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<Worker> _workers = [];
void push(Worker worker){
_workers.add(worker);
}
Future<List<Worker>> 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;
}
}
}