-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calculator.php
56 lines (53 loc) · 1.39 KB
/
Calculator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/**
* Created by PhpStorm.
* User: dobrodeev
* Date: 01.08.2018
* Time: 16:28
*/
class Calculator
{
private $first;
private $second;
private $action;
public function __construct($first, $second, $action)
{
$this->first = $first;
$this->second = $second;
$this->action = $action;
}
public function resultAction()
{
$variant = $this->action;
echo '<h5>Result:<h5>';
switch ($variant)
{
case '+':
echo $this->first+$this->second;
break;
case '-':
echo $this->first-$this->second;
break;
case '*':
echo $this->first*$this->second;
break;
case '/':
if ($this->second == 0)
{
echo 'Division by zero. <br>';
break;
}
echo $this->first/$this->second;
break;
case '%':
echo $this->first % $this->second;
break;
case 'x^2+y^2':
echo $this->first * $this->first + $this->second * $this->second;
break;
case 'x^3+y^3':
echo $this->first * $this->first * $this->first + $this->second * $this->second *$this->second;
break;
}
}
}