Guest User

Untitled

a guest
Apr 23rd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. //can have code outside the class
  2. void main() {
  3. Person person1 = new Person('A', 100000.0);
  4. Person person2 = new Person('B', 110000.0, empType: EmployeeType.CONTRACT);
  5.  
  6. print(person1.salary);
  7. person1.giveRaise(7);
  8. print(person1);
  9. }
  10.  
  11. //use lowerCamelCase for constant variables.
  12. //Begin global constant names with prefix "k"
  13. const int kConversionRate = 65;
  14.  
  15. double getINRSalary(double salary) => salary * kConversionRate;
  16.  
  17. enum EmployeeType { FTE, CONTRACT, INTERN }
  18.  
  19. class Person {
  20. String name;
  21. double _salary;
  22. EmployeeType empType;
  23.  
  24. //getter
  25. double get salary => _salary; // this makes _salary read only
  26.  
  27. Person(this.name, this._salary, {this.empType = EmployeeType.FTE});
  28.  
  29. void giveRaise(int percent) {
  30. _salary *= (100 + percent) / 100;
  31. }
  32.  
  33. @override
  34. String toString() => 'Employee $name has salary $_salary';
  35. }
Add Comment
Please, Sign In to add comment