Webbserverprogrammering 1

Show sourcecode

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

webbserverprogrammering/exercises/repetition/

ovning_1.php
ovning_2.php
ovning_3a.php
ovning_3b.php
ovning_3c.php
ovning_4.php
ovning_5.php
ovning_6.php
ovning_7.php

ovning_6.php

64 lines UTF-8 Windows (CRLF)
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/dark.css">
  <title>Övning 6</title>
</head>
<body>
  <?php
    
class Ball {
      private 
$radius;

      public function 
__construct($radius) {
        
$this->radius $radius;
      }

      public function 
get_radius() {
        return 
$this->radius;
      }
    }

    class 
BasketBall extends Ball {
      public function 
get_info() {
        echo 
"detta är en basketboll";
      }
    }

    class 
TennisBall extends Ball {
      public function 
__construct($radius$color) {
        
$this->radius $radius;
        
$this->color $color;
      }
      public function 
get_radius() {
        return 
$this->radius;
      }
      public function 
get_color() {
        return 
$this->color;
      }
      public function 
get_info() {
        echo 
"detta är en tennisboll";
      }
    }

    
$small_ball = new Ball(2);
    
$medium_ball = new Ball(5);
    
$big_ball = new Ball(12);
    
$basket_ball = new BasketBall(6);
    
$tennis_ball = new TennisBall(1"lime");

    echo 
"Lilla bollens radius är ".$small_ball->get_radius();
    echo 
"<br>";
    echo 
"Medium bollens radius är ".$medium_ball->get_radius();
    echo 
"<br>";
    echo 
"Stora bollens radius är ".$big_ball->get_radius();
    echo 
"<br>";
    echo 
"En boll har radien ".$basket_ball->get_radius()." -- ";
    echo 
$basket_ball->get_info();
    echo 
"<br>";
    echo 
"En boll har radien ".$tennis_ball->get_radius()." och färgen ".$tennis_ball->get_color()." -- ";
    echo 
$tennis_ball->get_info();
  
?>
</body>
</html>