Skip to content

Instantly share code, notes, and snippets.

@graphicbeacon graphicbeacon/main.dart
Last active Apr 15, 2018

Embed
What would you like to do?
A basic program written in the Dart programming language
class Person {
String _name;
int _age;
String occupation;
List<String> hobbies;
Person(this._name, this._age, [ this.occupation, this.hobbies ]);
String getIntro() => 'Name: $_name. Age: $_age. Occupation: $occupation';
String getInterests() {
if (this.hobbies == null) return '$_name has not listed any hobbies :-(';
var interests = '';
for(var i = 0; i < hobbies.length; i++) {
if (i == hobbies.length - 1) {
interests += 'and ${hobbies[i]}';
} else {
interests += '${hobbies[i]}, ';
}
}
return interests;
}
}
main() {
Person john = new Person('John Doe', 25)
..occupation = 'Doctor'
..hobbies = ['Singing', 'Biking', 'Travelling'];
print(john.getInterests());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.