Webbserverprogrammering 1

Show sourcecode

The following files exists in this folder. Click to view.

webbserverprogrammering/exercises/classes/

ovn_cls1.php
ovn_cls2.php
ovn_cls3.php
ovn_cls4.php
ovn_cls5.php
ovn_cls6.php
ovn_cls7.php

ovn_cls7.php

91 lines UTF-8 Windows (CRLF)
<?php

class Ball
{
    
// Properties
    
private $color;
    private 
$radius;
    private static 
$no_balls;

    
// Methods
    
public function __construct($color$radius)
    {
        
$this->color $color;
        
$this->radius $radius;
        
self::$no_balls += 1;
    }

    public function 
get_ball_color()
    {
        return 
$this->color;
    }
    public function 
get_ball_radius()
    {
        return 
$this->radius;
    }

    public function 
get_ball()
    {
        return 
$this;
    }

    public static function 
all_balls() {
        return 
self::$no_balls;
    }
}

class 
BallMaterial extends Ball
{
    
// Properties
    
private $ball_material;

    public function 
__construct($color$radius$ball_material)
    {
        
parent::__construct($color$radius);
        
$this->ball_material $ball_material;
    }

    public function 
get_ball_material()
    {
        return [
$this->ball_material];
    }

    public function 
get_ball()
    {
        return 
$this;
    }
}

class 
BallWeight extends BallMaterial
{
    
// Properties
    
private $ball_weight;

    public function 
__construct($color$radius$ball_material$ball_weight)
    {
        
parent::__construct($color$radius$ball_material);
        
$this->ball_weight $ball_weight;
    }
    public function 
get_ball_weight()
    {
        return [
$this->ball_weight];
    }

    public function 
get_ball()
    {
        return 
$this;
    }
}



$ball1 = new BallWeight("red""12""stål""2000");

$ball2 = new BallWeight("blue""12""gummi""100");

$ball3 = new BallWeight("red""12""tyg""10");

$balls = [$ball1->get_ball(), $ball2->get_ball(), $ball3->get_ball()];
print_r($balls);
echo 
'<br>';
echo 
"Det finns " Ball::all_balls() . " bollar!";