/
pr3.php
73 lines (56 loc) · 1.28 KB
/
pr3.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
$kid = new Kid();
$kid->setName('ドラミ');
$kid->setSex('girl');
echo $kid->showName();
$kid2 = new Kid();
$kid2->setName('ジャイアン');
$kid2->setSex('boy');
echo $kid2->showName();
class Kid{
private $name;
private $sex;
private $age;
function __construct(){
$this->name = 'Seed';
$this->sex = 'boy';
}
public function setName($namae){
$this->name=$namae;
}
public function getName(){
return $this->name;
}
public function setSex($gender){
return $this->sex = $gender;
}
public function getSex(){
return $this->sex;
}
public function setAge($years){
$this->age=$years;
}
public function getAge(){
return $this->age;
}
public function showName(){
if($this->age<12){
if ($this->sex == 'boy') {
return $this->name.'くん<br>';
}elseif($this->sex == 'girl') {
return $this->name.'ちゃん<br>';
}else{
return $this->name.'の性別不明ですー。';
}
}else{
if ($this->sex == 'boy') {
return $this->name.'君<br>';
}elseif($this->sex == 'girl') {
return $this->name.'さん<br>';
}else{
return $this->name.'の性別不明ですー。';
}
}
}
}
?>