Question:
Date: 09-04-2020 17:10:23
(In Spanish)
Votes: -1 - Answers: 2 - Views: 4 Share on: Google Facebook Twitter LinkedIn Link
Se requiere extraer el numero mayor de 3 números, utilizando herencia de clases con php y html, pero me arroja error[Unresolved]
class Valores { protected $valor1; protected $valor2; protected $valor3; protected $res; public function cargar1($v1) { $this->valor1=$v1; } public function cargar2($v2) { $this->valor2=$v2; } public function cargar3($v3) { $this->valor3=$v3; } public function imprimir() { return $this->res; } } class mayor extends Valores { public function operar() { if(valor1 >= valor2 && valor1 >= valor3) { $this->res=$this->valor1; echo "El numero es mayor"; } elseif($valor2 > $valor1 && $valor2 > $valor3) { $this->res=$this->valor2; echo "el numero es mayor"; } else { $this->res=$this->valor3; echo "El numero mayor es: "; } } } ?> <html> <head> <title>Numero mayor</title> </head> <body> <?php $mayor = new mayor(); $mayor -> cargar1("2"); $mayor -> cargar2("5"); $mayor -> cargar3("9"); $mayor -> operar(); echo "<hr>"; ?> </body> </html><?php
Votes: -1 - Answers: 2 - Views: 4 Share on: Google Facebook Twitter LinkedIn Link
Answers:
-
-
Date: 13-04-2020 11:52:36 Tienes múltiples erorres de sintáxis, sobre todo en las sentencias dentro de Valores::operar.
<?php declare(strict_types=1); /** * Class Valores */ abstract class Valores { /** @var int */ protected $valor1; /** @var int */ protected $valor2; /** @var int */ protected $valor3; /** @var float */ protected $res; /** * @return int */ public function getValor1(): int { return $this->valor1; } /** * @param int $valor1 */ public function setValor1(int $valor1): void { $this->valor1 = $valor1; } /** * @return int */ public function getValor2(): int { return $this->valor2; } /** * @param int $valor2 */ public function setValor2(int $valor2): void { $this->valor2 = $valor2; } /** * @return int */ public function getValor3(): int { return $this->valor3; } /** * @param int $valor3 */ public function setValor3(int $valor3): void { $this->valor3 = $valor3; } /** * @return float */ abstract public function getRes(): float; /** * @param float $res */ public function setRes(float $res): void { $this->res = $res; } } /** * Class Mayor */ class Mayor extends Valores { /** @inheritDoc */ public function getRes(): float { $values = [$this->getValor1(), $this->getValor2(), $this->getValor3()]; asort($values); return array_pop($values); } } $mayor = new Mayor(); $mayor->setValor1(2838438); $mayor->setValor2(343); $mayor->setValor3(495498); ?> <!DOCTYPE html> <html> <head> <title>Numero mayor</title> </head> <body> <p>El mayor es: <span style="font-weight: bold"><?= $mayor->getRes() ?></span></p> <hr/> </body> </html>
Votes: 1 - Link answer
To actively participate in the community first must authenticate, enter the system.Sign In