Guest User

Untitled

a guest
Aug 16th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. class School {
  2. constructor(name, level, numberOfStudents) {
  3. this._name = name;
  4. this._level = level;
  5. this._numberOfStudents = 0;
  6. }
  7. get name() {
  8. return this._name;
  9. }
  10. get level() {
  11. return this._level;
  12. }
  13. get numberOfStudents() {
  14. return this._numberOfStudents;
  15. }
  16. quickFacts() {
  17. console.log(`${this._name} educates ${this._numberOfStudents} at the ${this._level} school level.`)
  18. }
  19. static pickSubstituteTeacher(substituteTeachers) {
  20. const teacherNumber = Math.floor(Math.random() * substituteTeachers.length);
  21. return substituteTeachers[teacherNumber];
  22. }
  23. set numberOfStudents(newStudent) {
  24. if (typeof newStudent === 'Number') {
  25. this._numberOfStudents = newStudent;
  26. } else {
  27. console.log(`Invalid input: ${this._numberOfStudents} must be set to a Number`);
  28. }
  29. }
  30. }
  31. class PrimarySchool extends School {
  32. constructor(name, numberOfStudents, pickupPolicy) {
  33. super(name, 'primary', numberOfStudents);
  34. this._pickupPolicy = pickupPolicy;
  35. }
  36. get pickupPolicy() {
  37. return this._pickupPolicy;
  38. }
  39. }
  40. class HighSchool extends School {
  41. constructor(name, numberOfStudents, sportsTeams) {
  42. super(name, 'high', numberOfStudents);
  43. this._sportsTeams = sportsTeams;
  44. }
  45. get sportsTeams() {
  46. console.log(this._sportsTeams);
  47. }
  48. }
  49. const lorraineHansbury = new PrimarySchool('Lorraine Hansbury', 514, 'Students must be picked up by a parent, guardian, or a family member over the age of 13');
  50. lorraineHansbury.quickFacts();
  51. School.pickSubstituteTeacher(['Jamal Crawford', 'Lou Williams', 'J.R. Smith', 'James Harden', 'Jason Terry', 'Manu Ginobli']);
  52. console.log(School.substituteTeachers);
  53. const alSmith = new HighSchool('Al E. Smith', 415, ['Baseball', 'Basketball', 'Volleyball', 'Track and Field']);
  54. alSmith.sportsTeams;
Add Comment
Please, Sign In to add comment