-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
49 lines (46 loc) · 1.29 KB
/
index.php
File metadata and controls
49 lines (46 loc) · 1.29 KB
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
<?php
class TempTracker{
private $tempList = [];
private $max = null;
private $min = null;
private $sum =null;
private $count = 0;
//add temp to list
public function setTemp($temperature){
//temperature must be an integer or float!
if(!is_int($temperature) && !is_float($temperature) ) return 0;
// throw new Exception('temperature must be an integer or float!');
$this->tempList[] = $temperature;
return 1;
}
//Get List
public function getList(){
return $this->tempList;
}
//Get Max
public function getMax(){
return $this->max;
}
// Get min
public function getMin(){
return $this->min;
}
// Get mean
public function getMean(){
return $this->count === 0 ? null : $this->sum / $this->count;
}
// insert new temperature
public function insert($temperature){
if(!$this->setTemp($temperature)) return;
if ($this->count === 0) {
$this->sum = $this->max = $this->min = $temperature;
$this->count = 1;
} else {
$this->min = min($this->min, $temperature);
$this->max = max($this->max, $temperature);
$this->sum += $temperature;
$this->count++;
}
}
}
?>