Skip to content

Commit

Permalink
28.05
Browse files Browse the repository at this point in the history
  • Loading branch information
ursinn committed May 28, 2020
1 parent 786c693 commit 3276812
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 0 deletions.
44 changes: 44 additions & 0 deletions 28.05/Ablauf.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* This is free and unencumbered software released into the public domain.
*
* Anyone is free to copy, modify, publish, use, compile, sell, or
* distribute this software, either in source code form or as a compiled
* binary, for any purpose, commercial or non-commercial, and by any
* means.
*
* In jurisdictions that recognize copyright laws, the author or authors
* of this software dedicate any and all copyright interest in the
* software to the public domain. We make this dedication for the benefit
* of the public at large and to the detriment of our heirs and
* successors. We intend this dedication to be an overt act of
* relinquishment in perpetuity of all present and future rights to this
* software under copyright law.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* For more information, please refer to <http://unlicense.org>
*/

require_once ('Auto.class.php');

$auto1 = new Auto("VW", "Polo", 154);
$auto2 = new Auto("Porsche", "911 Carrera 4S", 297);

$auto1->beschleunigen(10);
$auto1->beschleunigen(7);
$auto1->bremsen(5);
$auto1->bremsen(32);

$auto2->beschleunigen(26);
$auto2->bremsen(7);

$auto3 = clone $auto2;
$auto3->ausgabe();

79 changes: 79 additions & 0 deletions 28.05/Auto.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php
/**
* This is free and unencumbered software released into the public domain.
*
* Anyone is free to copy, modify, publish, use, compile, sell, or
* distribute this software, either in source code form or as a compiled
* binary, for any purpose, commercial or non-commercial, and by any
* means.
*
* In jurisdictions that recognize copyright laws, the author or authors
* of this software dedicate any and all copyright interest in the
* software to the public domain. We make this dedication for the benefit
* of the public at large and to the detriment of our heirs and
* successors. We intend this dedication to be an overt act of
* relinquishment in perpetuity of all present and future rights to this
* software under copyright law.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* For more information, please refer to <http://unlicense.org>
*/

class Auto
{
private $marke;
private $modell;
private $geschwindigkeit = 0;
private $geschw_max;
private $bremsentemp = 20;

public function __construct(string $marke, string $modell, int $geschw_max)
{
$this->marke = $marke;
$this->modell = $modell;
$this->geschw_max = $geschw_max;
}

public function __destruct()
{
echo $this->marke . " (" . $this->modell . ") wurde von der Polizei angehalten und leider stillgelegt \n\n";
}

public function beschleunigen(int $time) {
$this->geschwindigkeit += 10 * $time;
if ($this->geschwindigkeit > $this->geschw_max)
$this->geschwindigkeit = $this->geschw_max;
echo $this->marke . " (" . $this->modell . ") beschleunigt " . $time . " und fährt jetzt " . $this->geschwindigkeit . " km/h \n\n";
}

public function bremsen(int $time) {
$this->geschwindigkeit -= 5 * $time;
if ($this->geschwindigkeit < 0)
$this->geschwindigkeit = 0;
$this->bremsentemp += 5 * $time;
echo $this->marke . " (" . $this->modell . ") bremst " . $time . " und fährt noch " . $this->geschwindigkeit . " km/h \n\n";
if ($this->bremsentemp > 150)
echo "Autsch! Die Bremsen sind zu warm (Wert: " . $this->bremsentemp .") \n\n";
}

public function __clone()
{
$this->modell = $this->modell . " - Klon";
}

public function ausgabe() {
echo "Automarke: " . $this->marke . "\n";
echo "Modell: " . $this->modell . "\n";
echo "Höchstgeschwindigkeit: " . $this->geschw_max . "\n";
echo "momentane Geschwindikeit: 225". "\n";
echo "Bremsentemperatur: " . $this->bremsentemp . "\n\n";
}

}

0 comments on commit 3276812

Please sign in to comment.