SHARE
TWEET

Untitled

a guest Jun 25th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. class Materia{
  3.     $nombre;
  4.     public function __construct($id,$nombre){
  5.         $this->id=$id;
  6.         $this->nombre=$nombre;
  7.     }
  8. }
  9. ?>
  10. <?php
  11. class Alumno{
  12.  $nombre;
  13.  $misMaterias=array();
  14.  public fucntion __construct($nombre){
  15.     $this->nomre=$nombre;
  16.  }
  17.  public function getMaterias(){
  18.     return $this->misMaterias;
  19.  }
  20.  public function addMateria(Materia $pMateria){
  21.   $this->misMaterias[] = $pMateria;
  22.  }
  23. }    
  24. ?>
  25. <?php
  26. $mates=new Materia('M1','matematicas');
  27. $nuevoAlumno= new Alumno('Chris');
  28. $nuevoAlumno->addMateria($mates);
  29. $nuevoAlumno->addMateria($mates);
  30. var_dump($nuevoAlumno);
  31. ?>
  32.      
  33. public function addMateria(Materia $pMateria){
  34.   foreach($this->misMaterias as $currentMateria){
  35.     //Si existe la materia, no la aƱadimos al array y salimos
  36.     if($currentMateria->getId() == $pMateria->getId()) return;
  37.  
  38.     $this->misMaterias[] = $pMateria;  
  39.  }
  40.      
  41. public function addMateria(Materia $pMateria){
  42.   $this->misMaterias[$pMateria->getId()] = $pMateria;  
  43.  }
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