Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. //zad1
  2.  
  3. function Student(imie, nazwisko, oceny){
  4. this.imie = imie;
  5. this.nazwisko = nazwisko;
  6. this.oceny = [];
  7. }
  8.  
  9. var student1 = new Student('Weronika', 'Baranowska');
  10.  
  11. var a = [];
  12.  
  13. Student.prototype.dodajOcene = function(a){
  14. this.oceny[this.oceny.length] = a;
  15. }
  16.  
  17. student1.dodajOcene(3.5);
  18. student1.dodajOcene(5);
  19. student1.dodajOcene(4.5);
  20.  
  21. console.log(student1);
  22.  
  23. var suma = 0;
  24.  
  25. Student.prototype.sredniaOcen = function(){
  26. for(var i = 0; i < this.oceny.length; i++)
  27. suma+=this.oceny[i];
  28. var srednia = suma/this.oceny.length;
  29. console.log(this.imie, this.nazwisko, srednia);
  30. }
  31.  
  32. student1.sredniaOcen();
  33.  
  34. //zad2
  35.  
  36. class StudentX{
  37. constructor(imie, nazwisko, oceny){
  38. this.imie = imie;
  39. this.nazwisko = nazwisko;
  40. this.oceny = [];
  41. }
  42.  
  43. sredniaOcenX(a){
  44. var suma = 0;
  45. for(var i = 0; i < this.oceny.length; i++)
  46. suma+=this.oceny[i];
  47. var srednia = suma/this.oceny.length;
  48. return srednia;
  49. }
  50.  
  51. dodajOceneX(a){
  52. this.oceny[this.oceny.length] = a;
  53. }
  54. weekend(d)
  55. {
  56. var c = 'Jest weekend';
  57. console.log(c);
  58. console.log(d);
  59.  
  60. }
  61. }
  62.  
  63. var student2 = new StudentX('Katarzyna', 'Kowalska');
  64. student2.dodajOceneX(2);
  65. student2.dodajOceneX(4);
  66. student2.dodajOceneX(3.5);
  67.  
  68. console.log(student2);
  69. console.log(student2.imie, student2.nazwisko, student2.sredniaOcenX());
  70.  
  71. //zad3
  72.  
  73. class PilnyStudent extends StudentX{
  74. constructor(imie, nazwisko, oceny){
  75. super(imie, nazwisko, oceny)
  76. this.imie = imie;
  77. this.nazwisko = nazwisko;
  78. this.oceny = [];
  79. }
  80. /*
  81. weekend(){
  82. super.weekend('Jest weekend.');
  83. }
  84. */
  85. uczSie(){
  86. super.weekend('Ucz siÄ™.');
  87. }
  88. }
  89.  
  90. class RozrywkowyStudent extends StudentX{
  91. constructor(imie, nazwisko, oceny){
  92. super(imie, nazwisko, oceny)
  93. this.imie = imie;
  94. this.nazwisko = nazwisko;
  95. this.oceny = [];
  96. }
  97.  
  98. /*
  99. weekend(){
  100. super.weekend('Jest weekend.');
  101. }
  102. */
  103. balanguj(){
  104. super.weekend('Balanguj.');
  105. }
  106. }
  107.  
  108. var student3 = new PilnyStudent('Agnieszka', 'Nowak', [5, 5, 4.5]);
  109. var student4 = new RozrywkowyStudent('Monika', 'Kwiatkowska', [4, 3, 3.5]);
  110.  
  111. console.log(student3.imie);
  112. student3.uczSie();
  113.  
  114. console.log(student4.imie);
  115. student4.balanguj();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement