<?php declare(strict_types=1); $userScoreA = 80; $userScoreB = 79; function judgeScore(int $score = 0): string { if($score >= 80) { $result = "{$score}点は合格です"; } else { $result = "{$score}点は不合格です"; } return $result; } // echo judgeScore($userScoreA); // echo judgeScore($userScoreB); // echo judgeScore(); function shopping(int $price, int $quantity) :string { $total = $price * $quantity; $result = "合計金額は{$total}円です"; return $result; } // echo shopping(500, 3); function movie(int $age): string { if($age <=12) { return "チケット料金は800円です"; } else if ( $age <= 64 ) { return "チケット料金は1800円です"; } else { return "チケット料金は1100円です"; } } // echo movie(10); function bmi(float $height, int $weight): string { $m = $height / 100; $bmi = $weight / ($m * $m); $roundBmi = round($bmi, 1); if($roundBmi < 18.5) { return "BMIは{$roundBmi}です。低体重です"; } else if ($roundBmi < 25) { return "BMIは{$roundBmi}です。普通体重です"; } else { return "BMIは{$roundBmi}です。肥満です"; } } // echo bmi(164,84); class BookStore{ public string $storename; public string $bookname; public string $outher; public function __construct(string $storename, string $bookname) { $this->storename = $storename; $this->bookname = $bookname; } public function buy() { echo "本を売りました"; } } // $store1 = new BookStore("未来書店","走れメロス"); // echo $store1->storename; // $store1->buy(); // echo $store1->bookname; class Cafe{ public string $storename; public string $menu; public int $price; private int $int = 0; function __construct(string $storename, string $menu, int $price) { $this->storename = $storename; $this->menu = $menu; $this->price = $price; } public function order() : void { echo "{$this->menu}を注文しました"; } } // $cafe1 = new Cafe("コメダ","コーヒー", 300); // $cafe1->order(); class Hospital { public string $name; public string $sinryouka; private int $price; function __construct(string $name, string $sinryouka, int $price) { $this->name = $name; $this->sinryouka = $sinryouka; $this->price = $price; } function priceFunc(): int { return $this->price; } function price(): void{ echo "{$this->sinryouka}で診察しました。料金は{$this->priceFunc()}です。"; } } // $hospital1 = new Hospital("阪大","免疫内科",5000); // $hospital2 = new Hospital("京大","消化器内科",3000); // $hospital1->price(); // $hospital2->price(); class Hotel{ public string $name; public string $type; private int $price; function __construct(string $name, string $type, int $price) { $this->name = $name; $this->type = $type; $this->price = $price; } function price(): int { return $this->price; } function checkin(): void { echo "{$this->type}タイプのお部屋にチェックインしました。料金は{$this->price()}円です"; } } // $checkin1 = new Hotel("アパホテル", "シングル", 8000); // $checkin2 = new Hotel("リゾートホテル", "ダブル", 20000); // $checkin1->checkin(); // $checkin2->checkin(); class Restaurant{ public string $name; public string $menu; private int $price; function __construct(string $name,string $menu,int $price) { $this->name = $name; $this->menu = $menu; $this->price = $price; } function price(): int{ return $this->price; } function order(): void { echo "{$this->name}を注文しました。お値段は{$this->price()}円です。"; } } $order1= new Restaurant("都ホテル", "スイートポテト", 300); $order2= new Restaurant("ガスト", "スパゲティ", 780); $order3 = new Restaurant("王将","ぎょうざ",400); $order1->order(); $order2->order(); $order3->order();
You have javascript disabled. You will not be able to edit any code.
Generated using Vulcan Logic Dumper, using php 8.0.0