Exemplo n.º 1
0
    }
    function getArea()
    {
        return pow($this->lenght, 2);
    }
}
class Square extends Shape
{
}
class Triangle extends Shape
{
    protected $base = 4;
    protected $height = 7;
    function getArea()
    {
        return 0.5 * $this->base * $this->height;
    }
}
class Circle extends Shape
{
    protected $radius = 5;
    public function getArea()
    {
        return M_PI * pow($this->radius, 2);
    }
}
echo (new Triangle())->getArea();
echo (new Square('green'))->getColor();
$circle = new Circle();
echo $circle->getArea();
Exemplo n.º 2
0
<?php

define('CONT_NAME', 'value');
const OTHER_CONSTANT = 'value';
const CONSTANT_ARRAY = ['a' => 1, 'b' => 2];
class Circle
{
    const PI = 3.14;
    const DEFAULT_RADIUS = 3;
    public static function getArea($r = self::DEFAULT_RADIUS)
    {
        return self::PI * pow($r, 2);
    }
}
var_dump(Circle::getArea(5));
    }
    public function setSideLength($length)
    {
        $this->_sideLength = $length;
    }
    public function getArea()
    {
        return pow($this->_sideLength, 2);
    }
}
$myCircle = new Circle();
$myCircle->setColor("red");
$myCircle->fill();
$myCircle->setRadius(4);
echo "<h2>My Circle</h2>";
echo "<p>My circle has a radius of " . $myCircle->getRadius() . ".</p>";
echo "<p>It is " . $myCircle->getColor() . " and it is " . ($myCircle->isFilled() ? "filled" : "hollow") . ".</p>";
echo "<p>The area of my circle is: " . $myCircle->getArea() . ".</p>";
$mySquare = new Square();
$mySquare->setColor("green");
$mySquare->makeHollow();
$mySquare->setSideLength(3);
echo "<h2>My Square</h2>";
echo "<p>My square has a side length of " . $mySquare->getSideLength() . ".</p>";
echo "<p>It is " . $mySquare->getColor() . " and it is " . ($mySquare->isFilled() ? "filled" : "hollow") . ".</p>";
echo "<p>The area of my square is: " . $mySquare->getArea() . ".</p>";
?>

  </body>
</html>
Exemplo n.º 4
0
<?php

// circle.php
require_once "app_autoload.php";
$circle = new Circle(7);
echo "Dimensions: " . $circle->getDimensions() . "<br>";
echo "Perimeter (circumference): " . $circle->getPerimeter() . " (" . $circle->getCircumference() . ")<br>";
echo "Area: " . $circle->getArea() . "<br>";
Exemplo n.º 5
0
	<form action="" method="post">
	请输入|圆形|的半径:<br/>
	半径:<input type="text" name="radius" > <br/>
	<input type="submit" name="btn" value="计算">
	</form>
</body>
</html>

<?php 
include 'file_7_extraTraining.php';
class Circle extends Shape
{
    private $radius;
    function __construct($radius)
    {
        $this->radius = $radius;
    }
    function getArea()
    {
        return $this->radius * $this->radius * 3.14;
    }
    function getPerimeter()
    {
        return $this->radius * 2 * 3.14;
    }
}
if (isset($_POST["btn"])) {
    $circle1 = new Circle($_POST["radius"]);
    echo "圆形的周长:" . $circle1->getPerimeter() . "<br/>";
    echo "圆形的面积:" . $circle1->getArea() . "<br/>";
}
Exemplo n.º 6
0
<?php

require_once './src/shape.php';
require_once './src/circle.php';
require_once './src/cone.php';
require_once './src/cylinder.php';
$shape1 = new shape(3, 4, "niebieski");
$shape2 = new shape(6, 8, "czerwony");
$shape1->printInfo();
echo $shape1->distance($shape2);
$circle1 = new Circle(3, 4, "red", 5);
$circle2 = new Circle(6, 8, "blue", 2);
$circle1->printInfo();
echo "Odleglosc miedzy srodkami kol = " . $circle1->distance($circle2) . "<br><br>";
echo "Pole kola = " . $circle1->getArea() . "<br><br>";
echo "Obwod kola = " . $circle1->getPir() . "<br><br>";
$cone = new Cone(9, 12, "green", 5, 15);
$cone->printInfo();
echo "Pole stozka = " . $cone->getArea() . "<br><br>";
echo "Objetosc stozka = " . $cone->getVol() . "<br><br>";
$cylinder = new Cylinder(12, 16, "green", 10, 20);
$cylinder->printInfo();
echo "Pole walca = " . $cylinder->getArea() . "<br><br>";
echo "Objetosc walca = " . $cylinder->getVol() . "<br><br>";
Exemplo n.º 7
0
    }
    protected abstract function getArea();
}
class Square extends Shape
{
    protected $length = 4;
    public function getArea()
    {
        return pow($this->length, 2);
    }
}
class Triangle extends Shape
{
    protected $base = 4;
    protected $heigth = 7;
    public function getArea()
    {
        return 0.5 * $this->base * $this->heigth;
    }
}
class Circle extends Shape
{
    protected $radi = 5;
    public function getArea()
    {
        return M_PI * pow($this->radi, 2);
    }
}
$circle = new Circle();
echo $circle->getArea(), "\n";
Exemplo n.º 8
0
 public function testArea()
 {
     $circle = new Circle();
     $circle->setRadius(10);
     $this->assertEquals(M_PI * pow(10, 2), $circle->getArea());
 }
Exemplo n.º 9
0
/**
 * Created by PhpStorm.
 * User: ET
 * Date: 7/2/2015
 * Time: 3:34 PM
 */
function __autoload($class)
{
    include_once $class . '.php';
}
$s = new Sphere(23);
$o = new Oval(23, 11);
$c = new Cylinder(22, 7);
$circle = new Circle(12);
echo '<p>Radius of the circle is: ' . $circle->getRadius() . '</p>';
echo '<p>Circumference of the Circle: ' . $circle->getCircumference() . '</p>';
echo '<p>Area of the Circle: ' . $circle->getArea() . '</p>';
echo '-------------------------------------------';
echo '<p>Height of the Cylinder: ' . $c->getHeight() . '</p>';
echo '<p>Radius of the Cylinder: ' . $c->getRadius() . '</p>';
echo '<p>Area of the Cylinder: ' . $c->getArea() . '</p>';
echo '-------------------------------------------';
echo '<p>Area of the Oval: ' . $o->getArea() . '</p>';
echo '<p>Length of Semi-Major Axis of the Oval: ' . $o->getRadius() . '</p>';
echo '<p>Length of Semi-Minor Axis of the Oval: ' . $o->getRadius2() . '</p>';
echo '-------------------------------------------';
echo '<p>Area of the Sphere: ' . $s->getArea() . '</p>';
echo '-------------------------------------------';
echo '<p>Total Circle related created: ' . Circle::getCounter() . '</p>';
unset($c, $s, $circle);
echo '<p>Circles left: ' . Circle::getCounter() . '</p>';
Exemplo n.º 10
0
<?php

include "circle.php";
?>
<html>
<head>
	<title>Uji Class</title>
</head>
<body>
	<?php 
$lingkaran = new Circle();
$lingkaran->radius = 5;
$lingkaran->color = "Merah";
echo "<p>" . $lingkaran->getArea() . "</p>";
$lingkaran->toString();
?>
</body>
</html>