Last active
April 15, 2018 00:28
-
-
Save graphicbeacon/828203e8510be20439adef9e05461488 to your computer and use it in GitHub Desktop.
A basic program written in the Dart programming language
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
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