Created
March 16, 2021 15:40
-
-
Save aadomin/908675e271e60e38cd874219a238ab91 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Задание 2.10 - 1 | |
| // 1. Реализуйте класс Student (Студент), который будет наследоваться от класса User. | |
| // Класс должен иметь следующие свойства: | |
| // yearOfAdmission:DateTime (год поступления в вуз): инициализируется в конструкторе | |
| // currentCourse:int (текущий курс): рассчитывается след. образом - | |
| // из текущего года вычесть год поступления. чтобы получить годы из DateTime, | |
| // воспользуйтесь свойством DateTime.year | |
| class User { | |
| String name = ""; | |
| String surname = ""; | |
| @override | |
| toString() { | |
| return "Имя: $name, фамилия: $surname"; | |
| } | |
| } | |
| class Student extends User { | |
| DateTime yearOfAdmission = DateTime.now(); | |
| Student(String name, String surname, DateTime yearOfAdmission) { | |
| this.name = name; | |
| this.surname = surname; | |
| this.yearOfAdmission = yearOfAdmission; | |
| } | |
| int get currentCourse => DateTime.now().year - yearOfAdmission.year; | |
| @override | |
| toString() { | |
| return super.toString() + | |
| ", год поступления: ${yearOfAdmission.year}" + | |
| ", курс: $currentCourse"; | |
| } | |
| } | |
| main() { | |
| var student = Student("Joe", "Black", DateTime(2016)); | |
| print(student.toString()); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Пишите возвращаемые типы у функций. Это улучшает читаемость кода и есть в рекомендациях EffectiveDart
https://dart.dev/guides/language/effective-dart/design#do-annotate-return-types-on-function-declarations