-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclassdrill3.php
50 lines (39 loc) · 983 Bytes
/
classdrill3.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
<?
class Food{
static $foods =array();
function __construct($name,$calory){
$this->name =$name;
$this->calory = $calory;
}
static function input(){
echo "料理名を入力して下さい\n";
$name = trim(fgets(STDIN));
echo "カロリーを入力して下さい\n";
$calory = trim(fgets(STDIN));
$food = new Food($name, $calory);
array_push(Food::$foods,$food);
}
static function show_all_calory(){
$all_calory = 0;
$line = "------------\n";
echo $line;
foreach (Food::$foods as $food) {
echo $food->name . ":" . $food->calory . "kcal\n";
$allcalory += $food->calory;
}
echo $line;
echo "カロリー合計 : " . $allcalory . "kcal\n";
}
}
while (true) {
echo "[0] : カロリーを入力する\n";
echo "[1] : カロリーの合計を見る\n";
$input = trim(fgets(STDIN));
if($input == 0){
Food::input();
}else if ($input == 1){
Food::show_all_calory();
exit;
}
}
?>