-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrobot.php
More file actions
87 lines (71 loc) · 2.19 KB
/
robot.php
File metadata and controls
87 lines (71 loc) · 2.19 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/**
* Created by PhpStorm.
* User: himdd
* Date: 18/7/6
* Time: 上午7:08
*/
class xiaoHong {
public $lastAnswer = 0;
public $name ="小红";
public function calculate( $l, $r){
$answer= $l + $r -1;
$this->lastAnswer = $answer;
return $answer;
}
public function is_exist_mine($arr){
if( in_array($this->lastAnswer,$arr)){
print($this->name."说,这里有我的答案,我的答案是:".$this->lastAnswer."\n");
}else{
print($this->name."说,这里没有我的答案,我的答案是:".$this->lastAnswer."\n");
}
}
}
class xiaoMing {
public $lastAnswer = 0;
public $name ="小明";
public function calculate( $l, $r){
$answer= $l + $r;
$this->lastAnswer = $answer;
return $answer;
}
public function is_exist_mine($arr){
if( in_array($this->lastAnswer,$arr)){
print($this->name."说,这里有我的答案,我的答案是:".$this->lastAnswer."\n");
}else{
print($this->name."说,这里没有我的答案,我的答案是:".$this->lastAnswer."\n");
}
}
}
class Mock{
public static function deal(){
$xiaoHong = new xiaoHong();
$xiaoMing = new xiaoMing();
$l = 3;
$r = 6;
$hongAnswer = $xiaoHong->calculate($l, $r);
$mingAnswer = $xiaoMing->calculate($l, $r);
print("计算 $l + $r = ? \n");
print("小红的计算结果: ".$hongAnswer."\n");
print("小明的计算结果: ".$mingAnswer."\n");
print("\n\n");
//有他们答案的情况
$arrAnswer=[
$hongAnswer,
$mingAnswer
];
print("询问".implode(",",$arrAnswer)."中是否有他们的答案:\n");
$xiaoHong->is_exist_mine($arrAnswer);
$xiaoMing->is_exist_mine($arrAnswer);
print("\n\n");
//没有他们答案的情况
$ArrNoAnswer=[
1,
2,
];
print("询问".implode(",",$ArrNoAnswer)."中是否有他们的答案:\n");
$xiaoHong->is_exist_mine($ArrNoAnswer);
$xiaoMing->is_exist_mine($ArrNoAnswer);
}
}
Mock::deal();