Initial commit
This commit is contained in:
14
test/grammer/oop/01.dart
Normal file
14
test/grammer/oop/01.dart
Normal file
@@ -0,0 +1,14 @@
|
||||
class Human {
|
||||
String name = '';
|
||||
double weight = 0;
|
||||
double height = 0;
|
||||
}
|
||||
|
||||
void main(){
|
||||
Human toly = Human();
|
||||
toly.name = "捷特";
|
||||
toly.weight = 70;
|
||||
toly.height = 180;
|
||||
|
||||
print("Human: name{${toly.name},weight:${toly.weight}kg,height:${toly.height}cm}");
|
||||
}
|
||||
12
test/grammer/oop/02.dart
Normal file
12
test/grammer/oop/02.dart
Normal file
@@ -0,0 +1,12 @@
|
||||
class Human {
|
||||
String name = '';
|
||||
double weight = 0;
|
||||
double height = 0;
|
||||
|
||||
Human(this.name,this.weight,this.height);
|
||||
}
|
||||
|
||||
void main(){
|
||||
Human toly = Human("捷特",70,180);
|
||||
print("Human: name{${toly.name},weight:${toly.weight}kg,height:${toly.height}cm}");
|
||||
}
|
||||
52
test/grammer/oop/03.dart
Normal file
52
test/grammer/oop/03.dart
Normal file
@@ -0,0 +1,52 @@
|
||||
class Human {
|
||||
String name = '';
|
||||
double weight = 0;
|
||||
double height = 0;
|
||||
|
||||
Human(this.name, this.weight, this.height);
|
||||
|
||||
String info() {
|
||||
return "Human: name{${name},weight:${weight}kg,height:${height}cm}";
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
Human toly = Human("捷特", 70, 180);
|
||||
print(toly.info());
|
||||
|
||||
Human ls = Human("龙少", 65, 179);
|
||||
print(ls.info());
|
||||
|
||||
Human wy = Human("巫缨", 65, 179);
|
||||
print(wy.info());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
40
test/grammer/oop/04.dart
Normal file
40
test/grammer/oop/04.dart
Normal file
@@ -0,0 +1,40 @@
|
||||
class Human {
|
||||
String name = '';
|
||||
double weight = 0;
|
||||
double height = 0;
|
||||
|
||||
Human(this.name, this.weight, this.height);
|
||||
|
||||
double bmi() {
|
||||
double result = weight / ((height/100) * (height/100));
|
||||
return result;
|
||||
}
|
||||
|
||||
String info() {
|
||||
return "Human: name{${name},weight:${weight}kg,height:${height}cm}";
|
||||
}
|
||||
}
|
||||
|
||||
class Student extends Human {
|
||||
final String school;
|
||||
|
||||
Student(
|
||||
super.name,
|
||||
super.weight,
|
||||
super.height, {
|
||||
required this.school,
|
||||
});
|
||||
|
||||
@override
|
||||
String info() {
|
||||
String info = super.info() + "school: $school ";
|
||||
return info;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void main() {
|
||||
Student toly = Student("捷特", 70, 180,school: "安徽建筑大学");
|
||||
print(toly.bmi());
|
||||
print(toly.info());
|
||||
}
|
||||
Reference in New Issue
Block a user