-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcar.php
160 lines (112 loc) · 2.77 KB
/
car.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
class car
{
private $make_model;
private $price;
private $miles;
private $image;
function __construct($model,$amount,$drive,$image_url){
$this->make_model=$model;
$this->price=$amount;
$this->miles=$drive;
$this->image=$image_url;
}
function setMake($new_make){
$string_make =(string)$new_make;
if($string_make != ""){
$this->make_model=$string_make;
}
}
function getMake(){
return $this->make_model;
}
function setPrice($new_price){
$float_number=(float)$new_price;
if($floatnumber != 0){
$formatted_price = number_format($float_price, 2);
$this->price=$formated_price;
}
}
function getPrice(){
return $this->price;
}
function setMiles($new_miles){
$float_number=(float)$new_miles;
if($floatnumber !=0){
$formatted_miles = number_format($float_miles, 2);
$this->miles+$formated_price;
}
}
function getMiles(){
return $this->miles;
}
function setImage($new_image){
$this->image=$new_image;
}
function getImage(){
return $this->image;
}
function worthBuying($max_price,$max_mileage)
{
return $this->price< $max_price && $this->miles< $max_mileage;
}
}
$porche= new car("porche 2014",99090,98,"porsche.jpg");
$bmw= new car("BMW 2012",5609,500,"bmw.jpeg");
$ford= new car("Ford 1914",45689999,6000,"ford.jpg");
$cars=array($bmw,$ford,$porche);
$car_match_search=array();
if(empty($_GET['price']) && empty($_GET['miles'])){
echo "Please enter maximum number of miles & The maximum Price!!!!!!!!!!!!!!!";
}
elseif(empty($_GET['price']))
{
echo "Please enter a Price!!!!!!!!!!!!!!!";
}
elseif(empty($_GET['miles'])){
echo "Please enter maximum number of miles!!!!!!!!!!!!!!!";
}
else{
foreach ($cars as $car){
if($car->worthBuying($_GET['price'], $_GET['miles'])){
array_push($car_match_search,$car);
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Cars</title>
</head>
<body>
<?php
if (empty($car_match_search)){
echo "There are no cars to display";
}
else{
foreach ($car_match_search as $car){
$getmake=$car->getMake();
$getpic=$car->getImage();
$getprice=$car->getPrice();
$getmiles=$car->getMiles();
echo "<ul>";
echo "<li>";
echo $getmake;
echo "</li>";
echo "<img src='$getpic'/>";
echo "<ul>";
echo "<li>";
echo $getprice;
echo "</li>";
echo "<li>";
echo $getmiles;
echo "</li>";
echo "</ul>";
echo "</ul>";
}
}
?>
</body>
</html>