Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions autotest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
require("shapes.php");
$circle = new Circle(3.5);
$square = new Square(6);

function testResult($expected, $real) {
$exptected = (float) $expected;
$real = (float) $real;
echo "Eeldatav väärtus: ".$expected."<br>Tegelik väärtus: ".$real."<br>";
if ($exptected == $real) {
echo "Test OK.";
} else {
echo "Test nurjus.";
}
}

?>

<!doctype html>
<html style="background: gray; margin: 0; overflow: hidden;">
<body style="max-width: 768px; margin: 0 auto; background: snow; height: 96vh; padding: 15px; overflow-y: auto;">
<h1>Kujundite arvutaja</h1>
<h2>Automaattestidest</h2>
<p>Automaattestid on tehtud kindlate arvude järgi. Automaattestid testivad ainult
<i>background</i>-arvutamist ning objekt-orienteeritud koodi töötamist.
<br>
Automaattestide arvutamiseks anti klassidele ette järgmised arvud:
<br>
Ringi raadius: 3.5 üh;<br>
Ruudu külg: 6 üh.
</p>

<h2>Automaattestide tulemused</h2>
<p>Ringi diameeter<br><?=testResult(7, $circle->getDiameter())?><br></p>
<p>Ringi ümbermõõt<br><?=testResult(21.98, $circle->getCircum())?><br></p>
<p>Ringi pindala<br><?=testResult(38.465, $circle->getArea())?><br></p>
<br>
<p>Ruudu diameeter<br><?=testResult(6, $square->getLength())?><br></p>
<p>Ruudu ümbermõõt<br><?=testResult(24, $square->getCircum())?><br></p>
<p>Ruudu pindala<br><?=testResult(36, $square->getArea())?><br></p>


<br>
<a href="index.php">Tagasi pealehele.</a>
<br><br>
</body>
</html>
36 changes: 36 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
require("shapes.php");
$circle = new Circle($_GET["circle_radius"]);
$square = new Square($_GET["cube_l"]);

?>

<!doctype html>
<html style="background: gray; margin: 0; overflow: hidden;">
<body style="max-width: 768px; margin: 0 auto; background: snow; height: 100vh; padding: 15px;">
<h1>Kujundite arvutaja</h1>
<p>Vali järgnevast nimistust üks kujund, mida tahaksid arvutada. Sisesta selle kujundi
identifitseeriv väärtus, ning rakendus leiab selle järgi teised väärtused.</p>
<h2>Ringi arvutaja</h2>
<form id="circle">
<p>Ringi puhul on identifitseerivaks väärtuseks raadius.</p>
<label>Raadius:</label>
<input type="text" name="circle_radius"><br>
<label>Diameeter: <?=$circle->getDiameter()?> üh</label><br>
<label>Ümbermõõt: <?=$circle->getCircum()?> üh</label><br>
<label>Pindala: <?=$circle->getArea()?> üh</label><br>
<br><input type="submit" value="Arvuta">
</form>
<h2>Ruudu arvutaja</h2>
<form id="cube">
<p>Ruudu puhul on vajalik info ruudu külje pikkus.</p>
<label>Küljepikkus:</label>
<input type="text" name="cube_l"><br>
<label>Ümbermõõt: <?=$square->getCircum()?> üh</label><br>
<label>Pindala: <?=$square->getArea()?> üh</label><br>
<br><input type="submit" value="Arvuta">
</form>
<br>
<a href="autotest.php">Automaattestid klassidele on siin.</a>
</body>
</html>
50 changes: 50 additions & 0 deletions shapes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

class Circle {
private $radius;

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

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

public function getDiameter() {
return $this->radius*2;
}

public function getCircum() {
return $this->radius*2*3.14;
}

public function getArea() {
return $this->radius*$this->radius*3.14;
}

}

class Square {
private $length;

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

public function getLength() {
return $this->length;
}

public function getCircum() {
return $this->length*4;
}

public function getArea() {
return $this->length*$this->length;
}

}


?>