Skip to content

Instantly share code, notes, and snippets.

@graphicbeacon
Last active April 15, 2018 00:28
Show Gist options
  • Save graphicbeacon/828203e8510be20439adef9e05461488 to your computer and use it in GitHub Desktop.
Save graphicbeacon/828203e8510be20439adef9e05461488 to your computer and use it in GitHub Desktop.
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