SHARE
TWEET

Untitled

a guest Feb 27th, 2020 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 01 import ballerina/io;
  2. 02
  3. 03 type ExamResult object {
  4. 04
  5. 05 public string name;
  6. 06 public int mathsScore;
  7. 07 public int physicsScore;
  8. 08 public int chemistryScore;
  9. 09
  10. 10 public function __init(string name, int mathsScore,
  11. 11 int physicsScore, int chemistryScore) {
  12. 12 self.name = name;
  13. 13 self.mathsScore = mathsScore;
  14. 14 self.physicsScore = physicsScore;
  15. 15 self.chemistryScore = chemistryScore;
  16. 16 }
  17. 17
  18. 18 public function average() returns int {
  19. 19 return (self.mathsScore + self.physicsScore +
  20. 20 self.chemistryScore) / 3;
  21. 21 }
  22. 22
  23. 23 };
  24. 24
  25. 25 public function main() returns error? {
  26. 26 ExamResult result1 = new("sunil", 90, 85, 80);
  27. Chapter 3 Lists, Mappings, and ObjeCts
  28. 80
  29. 27 int avg = result1.average();
  30. 28 io:println("Sunil's exam score average: ", avg);
  31. 29 }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top