commit existing workshops

This commit is contained in:
boris
2024-10-17 00:35:53 +01:00
parent 4070dc5367
commit ed02b435fe
74 changed files with 1083 additions and 91 deletions

View File

@@ -0,0 +1,69 @@
<?php
class Converter {
/*
* Class for converting miles to kilometers, and vice versa
*/
var $number = 0, $fromUnit = '', $toUnit = '';
/*
* Constructor takes number and unit, then assigns
* them to corresponding properties
* @param int $number Number to be converted
* @param string $unit Conversion unit
*/
public function __construct($number = 0, $fromUnit = '', $toUnit = '') {
$this->number = $number;
$this->toUnit = $toUnit;
$this->fromUnit = $fromUnit;
}
/*
* Converts number and returns result
* @return string Result of conversion
*/
public function convert(): string {
if (is_numeric($this->number)) {
$result = $this->number;
switch ($this->fromUnit) {
case "KM":
switch ($this->toUnit) {
case "KM":
break;
case "Miles":
$result = $this->number * 0.621;
break;
case "Parsec":
$result = $this->number / 30856775812800;
break;
}
break;
case "Miles":
switch ($this->toUnit) {
case "KM":
$result = $this->number * 1.609;
break;
case "Miles":
break;
case "Parsec":
$result = $this->number / 19173511575400;
break;
}
break;
case "Parsec":
switch ($this->toUnit) {
case "KM":
$result = $this->number * 30856775812800;
break;
case "Miles":
$result = $this->number * 19173511575400;
break;
case "Parsec";
break;
}
break;
}
}
else {
$result = false;
}
return $result;
}
}