Paste Search Dynamic
Recent pastes
constructor
  1. class Bus {
  2.         constructor(name, passengers, ticketPrice){
  3.                 this.name = name;
  4.                 this.passengers = passengers;
  5.                 this.ticketPrice = ticketPrice;
  6. }
  7.         proceeds(){
  8.                 return this.passengers * this.ticketPrice;
  9. }
  10. }
  11.  
  12. class Express extends Bus {
  13.         constructor(name, passengers, ticketPrice, average, model){
  14.                 super(name, passengers, ticketPrice);
  15.                 this.average = average;
  16.                 this.model = model;
  17. }
  18.         proceeds(){
  19.                 return 0.05 * this.average * this.passengers * this.ticketPrice;
  20. }
  21. }
  22.  
  23. class Suburban extends Bus {
  24.         constructor(name, passengers, ticketPrice, distance){
  25.                 super(name, passengers, ticketPrice);
  26.                 this.distance = distance;
  27. }
  28.         proceeds(){
  29.                 return 0.01 * this.distance * this.passengers * this.ticketPrice;
  30. }
  31. }
  32.  
  33.  
  34. const someBus = new Express('BMW', 10, 5, 50, 'X5');
  35. const subBus = new Suburban('BMW', 10, 5, 150);
  36. console.log(someBus.proceeds());
  37. console.log(subBus.proceeds());
Parsed in 0.009 seconds