Webbserverprogrammering 1

Show sourcecode

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

webbserverprogrammering/exercises/classes/

classes.php
classes1.php
classes2.php
classes3.php
classes4.php
classes5.php

classes5.php

105 lines UTF-8 Windows (CRLF)
<!DOCTYPE html>
<html lang="sv">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Klasser 4</title>
</head>
<body>
  <?php
  
class Ball_d {
    
// Egenskaper
    
private $color;
    private 
$radius;

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

    private function 
get_color() {
      return 
$this->color;
    }

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

    public function 
info_1() {
      return 
"Färg: " $this->get_color() . 
           
", Radie: " $this->get_radius();
    }
  }

  class 
Ball_e extends Ball_d {
    
// Egenskaper
    
private $weight;

    
// Metoder
    
public function __construct($color$radius$weight) {
      
parent::__construct($color$radius);

      
$this->weight $weight;
      
    }

    private function 
get_weight() {
      return 
$this->weight;
    }

    public function 
info_2() {
      return 
"Färg: " $this->get_color() . 
           
", Radie: " $this->get_radius() . 
           
", Vikt: " $this->get_weight();
    }
  }

  class 
Ball_f extends Ball_d {
    
// Egenskaper
    
private $material;

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

    private function 
get_material() {
      return 
$this->material;
    }

    public function 
info_3() {
      return 
"Färg: " $this->get_color() . 
           
", Radie: " $this->get_radius() . 
           
", Vikt: " $this->get_material();
    }
  }

  
// Boll 1
  
$ball_1 = new Ball_d("Grön""1 dm");
  echo 
"Boll 1";
  echo 
"<hr style=\"border: none; border-top: 2px dotted black; width: 200px; margin-left: 0;\">";
  echo 
"Info: " $ball_1->info_1() . "<br>";
  echo 
"<hr style=\"width: 200px; margin-left: 0;\">" "<br>";

  
// Boll 2
  
$ball_2 = new Ball_e("Röd""2 dm""1 kg");
  echo 
"Boll 2";
  echo 
"<hr style=\"border: none; border-top: 2px dotted black; width: 200px; margin-left: 0;\">";
  echo 
"Info: " $ball_2->info_2() . "<br>";
  echo 
"<hr style=\"width: 200px; margin-left: 0;\">" "<br>";

  
// Boll 3
  
$ball_3 = new Ball_f("Blå""4 dm""Tungsten");
  
$weight_3 = new Ball_e("N/A""N/A""5172 kg");
  echo 
"Boll 3";
  echo 
"<hr style=\"border: none; border-top: 2px dotted black; width: 200px; margin-left: 0;\">";
  echo 
"Info: " $ball_3->info_3() . "<br>";
  echo 
"Vikt: "$weight_3->get_weight() . "<br>";
  echo 
"<hr style=\"width: 200px; margin-left: 0;\">" "<br>";
  
?>
 
</body>
</html>