PHP Classes

File: public/Classes/Calculator.php

Recommend this page to a friend!
  Classes of stefan   PHP Calculator   public/Classes/Calculator.php   Download  
File: public/Classes/Calculator.php
Role: Class source
Content type: text/plain
Description: Class source
Class: PHP Calculator
Calculate the result of multiple math operations
Author: By
Last change: resolve error ( and sin( in same term
Date: 2 years ago
Size: 856 bytes
 

Contents

Class file image Download
<?php
namespace Taschenrechner\Classes;
    use
Taschenrechner\Classes\Operationen\Operation;
class
Calculator {
    private
$operationen = array();
    public function
addOperation(int $reversepriority, Operation $operation) {
       
array_push($this->operationen, array("reversepriority" => $reversepriority, "object"=> $operation));
    }
    public function
calculate($term=0) {
        if(empty(
$this->operationen)) {
            throw new \
Exception("Keine Operationen für den Taschenrechner vorhanden");
        }

       
$termobject = new Term($term, $this->operationen, new Concatinator());
       
//Wenn der Term nicht gültig ist schmeiße nen Fehler
       
if(!$termobject->verify()) {
            throw new \
Exception("Bitte einen gültigen Term eingeben");
        }
       
//Löse den Term auf und gebe das Ergebnis zurück
       
$ergebnis = $termobject->resolve();
        return
$ergebnis;
    }
}