Skip to content

Commit a7c75e1

Browse files
committed
Template methon Hook implementation complete.
1 parent 52edf26 commit a7c75e1

File tree

5 files changed

+163
-0
lines changed

5 files changed

+163
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
//Client.php
3+
function __autoload($class_name)
4+
{
5+
include $class_name . '.php';
6+
}
7+
8+
class Client {
9+
private $buyTotal;
10+
private $gpsNow;
11+
private $mapNow;
12+
private $boatNow;
13+
private $special;
14+
private $zamCalc;
15+
16+
function __construct() {
17+
$this->setHTML();
18+
$this->setCost();
19+
$this->zamCalc=new ZambeziCalc();
20+
$this->zamCalc->templateMethod($this->buyTotal,$this->special);
21+
}
22+
23+
private function setHTML() {
24+
$this->gpsNow=$_POST['gps'];
25+
$this->mapNow=$_POST['map'];
26+
$this->boatNow=$_POST['boat'];
27+
}
28+
29+
private function setCost() {
30+
$this->buyTotal=$this->gpsNow;
31+
32+
foreach($this->mapNow as $value) {
33+
$this->buyTotal+= $value;
34+
}
35+
//Boolean
36+
$this->special = ($this->buyTotal >= 200);
37+
$this->buyTotal += $this->boatNow;
38+
}
39+
}
40+
41+
$worker=new Client();
42+
?>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
//IHook.php
3+
abstract class IHook
4+
{
5+
protected $purchased;
6+
protected $hookSpecial;
7+
protected $shippingHook;
8+
protected $fullCost;
9+
public function templateMethod($total,$special)
10+
{
11+
$this->purchased=$total;
12+
$this->hookSpecial=$special;
13+
$this->addTax();
14+
$this->addShippingHook();
15+
$this->displayCost();
16+
}
17+
protected abstract function addTax();
18+
protected abstract function addShippingHook();
19+
protected abstract function displayCost();
20+
}
21+
?>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
//ZambeziCalc.php
3+
class ZambeziCalc extends IHook
4+
{
5+
protected function addTax()
6+
{
7+
$this->fullCost = $this->purchased + ($this->purchased * .07);
8+
}
9+
protected function addShippingHook()
10+
{
11+
if(! $this->hookSpecial)
12+
{
13+
$this->fullCost += 12.95;
14+
}
15+
}
16+
protected function displayCost()
17+
{
18+
echo "Your full cost is $this->fullCost";
19+
}
20+
}
21+
?>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
To change this license header, choose License Headers in Project Properties.
3+
To change this template file, choose Tools | Templates
4+
and open the template in the editor.
5+
*/
6+
/*
7+
Created on : Feb 16, 2014, 11:59:32 AM
8+
Author : Anit Shrestha
9+
*/
10+
11+
12+
@charset "UTF-8";
13+
/* CSS Document */
14+
/*zambezi.css */
15+
/*D9C68F,F2DAC4,A69586,73635A,592D23*/
16+
body {
17+
background-color: #f2dac4;
18+
color: #73635a;
19+
font-family: Verdana, Geneva, sans-serif;
20+
font-size: 12px;
21+
}
22+
h1 {
23+
font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
24+
font-size:36px;
25+
}
26+
h2 {
27+
font-family: "Arial Black", Gadget, sans-serif;
28+
font-size: 18px;
29+
background-color: #592d23;
30+
color: #d9c68f;
31+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<link rel="stylesheet" type="text/css" href="zambezi.css">
6+
<title>Zambezi Trading Post</title>
7+
<body>
8+
<img src="zambezi.png" width="800" height="183" alt="zam">
9+
<h1>Adventure Outfitters</h1>
10+
<form action="Client.php" method="post">
11+
<h2>&nbsp;Equipment</h2>
12+
<h3>Navigation</h3>
13+
<p><strong>GPS</strong></p>
14+
<input type="radio" name="gps" value="98">
15+
&nbsp;Curiosity $98&nbsp;
16+
<input type="radio" name="gps" value="112">
17+
&nbsp;Cabot $112&nbsp;
18+
<input type="radio" name="gps" value="127">
19+
&nbsp;Boomer $127&nbsp;
20+
<input type="radio" name="gps" value="189">
21+
&nbsp;Livingston $189&nbsp;
22+
<p><strong>Maps</strong></p>
23+
<input type="checkbox" name="map[]" value="20">
24+
&nbspZambia $20&nbsp;
25+
<input type="checkbox" name="map[]" value="29">
26+
&nbspAngola $29&nbsp;
27+
<input type="checkbox" name="map[]" value="15">
28+
&nbspNamibia $15&nbsp;
29+
<input type="checkbox" name="map[]" value="15">
30+
&nbspBotswana $15&nbsp;
31+
<input type="checkbox" name="map[]" value="30">
32+
&nbspZimbabwe $30&nbsp;
33+
<input type="checkbox" name="map[]" value="27">
34+
&nbspMozambique $27<br/>
35+
<h2>&nbsp;River Craft (Daily Rental)</h2>
36+
<input type="radio" name="boat" value="55">
37+
&nbsp;White Water Kayak $55<br/>
38+
<input type="radio" name="boat" value="125">
39+
&nbsp;Motorized Canoe $125<br/>
40+
<input type="radio" name="boat" value="250">
41+
&nbsp;Zodiac $250<br/>
42+
<input type="radio" name="boat" value="495">
43+
&nbsp;Steam Launch $495
44+
<p/>
45+
<input type="submit" name="sender" value="Send order">
46+
</form>
47+
</body>
48+
</html>

0 commit comments

Comments
 (0)