public function testThatSumWorks()
 {
     $calculator = new Calculator();
     $this->assertEquals(2, $calculator->sum(1, 1));
 }
Example #2
0
 public function testSum()
 {
     $cal = new Calculator();
     $this->assertEquals(4, $cal->sum(2, 2));
 }
Example #3
0
<?php

Logger::log('Start');
$param1 = (int) (isset($_POST['param1']) ? $_POST['param1'] : $_GET['param1']);
$param2 = (int) (isset($_POST['param2']) ? $_POST['param2'] : $_GET['param2']);
Logger::log('Got params: %s and %s', [$param1, $param2]);
$calculator = new Calculator();
$result = $calculator->sum($param1, $param2);
echo '<div><b>Program "Calculator"</b><br><br>' . $param1 . ' + ' . $param2 . ' = <b>' . $result . '</b></div>';
Logger::log('Finish');
Example #4
0
        margin: 0 auto;
    }
    .container{
        margin-top: 70px;
    }
    </style>
</head>
<body>
<div class="container max-960">
    <div class="row">
        <div class="col-lg-4 col-md-4 col-sm-4 col-xs-12"></div>
        <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
            <div class="panel panel-default">
                <div class="panel-body">
                <div class="panel-heading"><h3>Calculation = <?php 
echo $cal->sum();
?>
</h3></div>
                    <form role="form">
                      <div class="form-group">
                        <label for="val1">Value 1</label>
                        <input type="number"  name="val1" class="form-control" placeholder=" Enter number">
                      </div>
                         <select class="form-control" name="operator">
                            <?php 
$cal->get_Operator();
?>
                        </select>
                      <div class="form-group">
                        <label for="val2">Value 2</label>
                        <input type="number"  name="val2" class="form-control" placeholder=" Enter number">
Example #5
0
<?php

class Calculator
{
    private $number;
    public function sum($number)
    {
        $this->number = $number;
        $odd = 0;
        $even = 0;
        for ($i = 0; $i <= $this->number; $i++) {
            if ($i % 2 == 1) {
                $odd = $odd + $i;
            } else {
                $even = $even + $i;
            }
        }
        echo "sum of odd number between 1 to " . $this->number . "is" . $odd . "<br />";
        echo "sum of even number between 1 to " . $this->number . "is " . $even;
    }
}
$calc = new Calculator();
$calc->sum(100);
 public function __invoke()
 {
     $input = file_get_contents(__DIR__ . "/../../input/Day12/Puzzle1");
     $calculator = new Calculator();
     $this->write("Total: " . $calculator->sum($input));
 }
Example #7
0
<?php

require_once 'lib/Calculator.php';
$calc = new Calculator();
echo $calc->sum(2, 2);