Ver Mensaje Individual
  #5 (permalink)  
Antiguo 16/12/2011, 07:04
Avatar de linuxzero
linuxzero
 
Fecha de Ingreso: noviembre-2011
Ubicación: Argentina
Mensajes: 778
Antigüedad: 12 años, 5 meses
Puntos: 160
Respuesta: Ejercicio de Programación Orientada a Objetos

Me olvide lo del recargo aca te dejo la clase y el php de la instancia modificados. Fijate si te sirve:

Código PHP:
Ver original
  1. <?php
  2.  
  3. class Pelicula
  4. {
  5.  
  6.     var $nombre;
  7.     var $ano;
  8.     var $director;
  9.     var $precio;
  10.     var $alquilada;
  11.     var $fechaDevolucion;
  12.     var $recargo;
  13.  
  14.     function __construct($nombre, $ano, $director, $precio, $alquilada, $fechaDevolucion)
  15.     {
  16.         $this->setNombre($nombre);
  17.         $this->setAno($ano);
  18.         $this->setDirector($director);
  19.         $this->setPrecio($precio);
  20.         $this->setAlquilada($alquilada);
  21.         $this->setFechaDevolucion($fechaDevolucion);
  22.         $this->setRecargo($this->calcularRecargo());
  23.     }
  24.  
  25.     public function getNombre()
  26.     {
  27.         return $this->nombre;
  28.     }
  29.  
  30.     public function setNombre($nombre)
  31.     {
  32.         $this->nombre = $nombre;
  33.     }
  34.  
  35.     public function getAno()
  36.     {
  37.         return $this->ano;
  38.     }
  39.  
  40.     public function setAno($ano)
  41.     {
  42.         $this->ano = $ano;
  43.     }
  44.  
  45.     public function getDirector()
  46.     {
  47.         return $this->director;
  48.     }
  49.  
  50.     public function setDirector($director)
  51.     {
  52.         $this->director = $director;
  53.     }
  54.  
  55.     public function getPrecio()
  56.     {
  57.         return $this->precio;
  58.     }
  59.  
  60.     public function setPrecio($precio)
  61.     {
  62.         $this->precio = $precio;
  63.     }
  64.  
  65.     public function getAlquilada()
  66.     {
  67.         return $this->alquilada;
  68.     }
  69.  
  70.     public function setAlquilada($alquilada)
  71.     {
  72.         $this->alquilada = $alquilada;
  73.     }
  74.  
  75.     public function getFechaDevolucion()
  76.     {
  77.         return $this->fechaDevolucion;
  78.     }
  79.  
  80.     public function setFechaDevolucion($fecha_devolucion)
  81.     {
  82.         $this->fechaDevolucion = $fecha_devolucion;
  83.     }
  84.  
  85.     public function getRecargo()
  86.     {
  87.         return $this->recargo;
  88.     }
  89.  
  90.     public function setRecargo($recargo)
  91.     {
  92.         $this->recargo = $recargo;
  93.     }
  94.  
  95.     private function calcularRecargo()
  96.     {
  97.         $datetime1 = new DateTime();
  98.         $datetime2 = new DateTime($this->getFechaDevolucion());
  99.         $interval = $datetime1->diff($datetime2);
  100.         return $this->getPrecio() * $interval->format('%a');
  101.     }
  102.  
  103. }
  104.  
  105. ?>

Código PHP:
Ver original
  1. <?php
  2. require_once 'pelicula.class.php';
  3. $pelicula = new Pelicula("Matrix", "2002", "Hnos Wasaski", 50, false, date("Y-m-d", strtotime("2011-12-17")));
  4.  
  5. echo $pelicula->getNombre() . "<br/>";
  6. echo $pelicula->getAno() . "<br/>";
  7. echo $pelicula->getDirector() . "<br/>";
  8. echo $pelicula->getPrecio() . "<br/>";
  9. echo ($pelicula->getAlquilada() ? 'SI' : 'NO'). "<br/>";
  10. echo $pelicula->getFechaDevolucion() . "<br />";
  11. echo $pelicula->getRecargo();
  12. ?>

Anda jugando con la fecha de devolucion para ver lo del recargo, si no es exactamente lo que buscas, pensa un poquito la logica y sale seguro ;)
__________________
Si todo fuera tan sencillo como un symfony cc la vida seria más fácil.
http://phpnico.wordpress.com