Last active
June 26, 2021 13:16
-
-
Save mikaelo/d227c00093d46eaba851b8b03d617bd2 to your computer and use it in GitHub Desktop.
This file contains 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
void main(List<String> arguments) { | |
print('Hello world!'); | |
var student = Student('mikhail', 'ushanov', DateTime(2018, 01, 01)); | |
print(student); | |
} | |
// 2.10 1 | |
class Student extends User { | |
DateTime yearOfAdmission; | |
int currentCourse; | |
Student(lastName, firstName, this.yearOfAdmission) | |
: super(lastName, firstName) { | |
currentCourse = DateTime.now().year - yearOfAdmission.year; | |
} | |
@override | |
String toString() { | |
return 'name: ${super.toString()}, yearOfAdmission: ${yearOfAdmission.year}, currentCourse: ${currentCourse}'; | |
} | |
} | |
class User { | |
String lastName; | |
String firstName; | |
User(this.lastName, this.firstName); | |
@override | |
String toString() { | |
return '$lastName $firstName'; | |
} | |
} |
This file contains 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
void main(List<String> arguments) { | |
print(Color.red); | |
var truck = Truck(Color.green); | |
print(truck.toString()); | |
truck.run(); | |
var sportcar = Sportcar(Color.yellow); | |
print(sportcar.toString()); | |
sportcar.run(); | |
var bike = Bike(Color.red); | |
print(bike.toString()); | |
} | |
abstract class Car { | |
double weight; | |
void run(); | |
} | |
class Truck extends Car with Painter, Engine{ | |
Truck(Color color) { | |
setColor(color); | |
} | |
@override | |
double get weight => 10; | |
@override | |
void run() { | |
runEngine(); | |
} | |
@override | |
String toString(){ | |
return 'Грузовик $colorName цвета'; | |
} | |
} | |
class Sportcar extends Car with Painter, Engine{ | |
Sportcar(Color color) { | |
setColor(color); | |
} | |
@override | |
double get weight => 2; | |
@override | |
void run() { | |
runEngine(); | |
} | |
@override | |
String toString(){ | |
return 'Спорткар $colorName цвета'; | |
} | |
} | |
class Bike with Painter{ | |
Bike(Color color) { | |
setColor(color); | |
} | |
@override | |
String toString(){ | |
return 'Велосипед $colorName цвета'; | |
} | |
} | |
enum Color {red, yellow, green} | |
const Map<Color, String> ColorName = { | |
Color.red: 'red', | |
Color.yellow: 'yellow', | |
Color.green: 'green', | |
}; | |
mixin Painter { | |
String _colorName; | |
void setColor(Color color) { _colorName = ColorName[color]; } | |
String get colorName => _colorName; | |
} | |
mixin Engine on Car { | |
int get enginePower => 100; | |
void runEngine() { | |
print('Двигатель работает. Максимальная скорость = ${enginePower / weight}'); | |
} | |
} | |
This file contains 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
void main(List<String> arguments) { | |
var printer = Printer(); | |
print(printer.print('string')); | |
print(printer.print(101)); | |
print(printer.print(DateTime.now())); | |
} | |
class Printer { | |
String print<T>(T data){ | |
return data.toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment