@ 2014-10-01T09:28:54Z <?php
abstract class Shape {
abstract protected function getArea();
public function toStringArea(){
return "The area of the " . get_called_class() . " is ".$this->getArea() . "\n";
}
public function toStringPerimeter(){
return "The perimeter of the " . get_called_class() . " is ".$this->getPerimeter() . "\n";
}
}
class Rectangle extends Shape{
private $l;
private $b;
public function __construct($l,$b) {
$this->l=$l;
$this->b=$b;
}
protected function getArea(){
return $this->l * $this->b;
}
protected function getPerimeter(){
return 2 * $this->l + 2 * $this->b;
}
}
class Triangle extends Shape{
private $l;
private $b;
public function __construct($l,$b) {
$this->l=$l;
$this->b=$b;
}
protected function getArea(){
return $this->l * $this->b * 0.5;
}
protected function getPerimeter(){
return $this->l + $this->b + sqrt($this->l * $this->l + $this->b * $this->l);
}
}
class Circle extends Shape{
private $r;
public function __construct($r) {
$this->r=$r;
}
protected function getArea(){
return $this->r*$this->r*3.14;
}
protected function getPerimeter(){
return $this->r*2*3.14;
}
}
echo'
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Show Hide Using Selectbox</title>
<style type="text/css">
.box{
padding: 20px;
display: none;
margin-top: 20px;
border: 1px solid #000;
}
.red{ background: #ff0000; }
.green{ background: #00ff00; }
.blue{ background: #0000ff; }
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("select").change(function(){
$( "select option:selected").each(function(){
if($(this).attr("value")=="red"){
$(".box").hide();
$(".red").show();
alert("Bam!");
}
if($(this).attr("value")=="green"){
$(".box").hide();
$(".green").show();
}
if($(this).attr("value")=="blue"){
$(".box").hide();
$(".blue").show();
}
});
}).change();
});
</script>
</head>
<body>
<div>
<select>
<option>Choose Color</option>
<option value="red">Red</option>
<option value="green">Green</option>
<option value="blue">Blue</option>
</select>
</div>
<div class="red box">You have selected <strong>red option</strong> so i am here</div>
<div class="green box">You have selected <strong>green option</strong> so i am here</div>
<div class="blue box">You have selected <strong>blue option</strong> so i am here</div>
';
echo '<p>';
$r = new Rectangle(5, 4);
echo $r->toStringArea() . "<br>";
echo $r->toStringPerimeter() . "<p>";
$c = new Circle(10);
echo $c->toStringArea() . "<br>";
echo $c->toStringPerimeter() . "<p>";
$t = new Triangle(5, 4);
echo $t->toStringArea() . "<br>";
echo $t->toStringPerimeter() . "<p>";
echo '
</body>
</html> ';
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 5.3.0 - 5.3.29 , 5.4.0 - 5.4.45 , 5.5.24 - 5.5.35 , 5.6.7 - 5.6.28 , 7.0.0 - 7.0.20 , 7.1.0 - 7.1.25 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.18 , 8.3.0 - 8.3.6 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Show Hide Using Selectbox</title>
<style type="text/css">
.box{
padding: 20px;
display: none;
margin-top: 20px;
border: 1px solid #000;
}
.red{ background: #ff0000; }
.green{ background: #00ff00; }
.blue{ background: #0000ff; }
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("select").change(function(){
$( "select option:selected").each(function(){
if($(this).attr("value")=="red"){
$(".box").hide();
$(".red").show();
alert("Bam!");
}
if($(this).attr("value")=="green"){
$(".box").hide();
$(".green").show();
}
if($(this).attr("value")=="blue"){
$(".box").hide();
$(".blue").show();
}
});
}).change();
});
</script>
</head>
<body>
<div>
<select>
<option>Choose Color</option>
<option value="red">Red</option>
<option value="green">Green</option>
<option value="blue">Blue</option>
</select>
</div>
<div class="red box">You have selected <strong>red option</strong> so i am here</div>
<div class="green box">You have selected <strong>green option</strong> so i am here</div>
<div class="blue box">You have selected <strong>blue option</strong> so i am here</div>
<p>The area of the Rectangle is 20
<br>The perimeter of the Rectangle is 18
<p>The area of the Circle is 314
<br>The perimeter of the Circle is 62.8
<p>The area of the Triangle is 10
<br>The perimeter of the Triangle is 15.708203932499
<p>
</body>
</html> Output for 5.0.0 - 5.0.5 , 5.1.0 - 5.1.6 , 5.2.0 - 5.2.17 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Show Hide Using Selectbox</title>
<style type="text/css">
.box{
padding: 20px;
display: none;
margin-top: 20px;
border: 1px solid #000;
}
.red{ background: #ff0000; }
.green{ background: #00ff00; }
.blue{ background: #0000ff; }
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("select").change(function(){
$( "select option:selected").each(function(){
if($(this).attr("value")=="red"){
$(".box").hide();
$(".red").show();
alert("Bam!");
}
if($(this).attr("value")=="green"){
$(".box").hide();
$(".green").show();
}
if($(this).attr("value")=="blue"){
$(".box").hide();
$(".blue").show();
}
});
}).change();
});
</script>
</head>
<body>
<div>
<select>
<option>Choose Color</option>
<option value="red">Red</option>
<option value="green">Green</option>
<option value="blue">Blue</option>
</select>
</div>
<div class="red box">You have selected <strong>red option</strong> so i am here</div>
<div class="green box">You have selected <strong>green option</strong> so i am here</div>
<div class="blue box">You have selected <strong>blue option</strong> so i am here</div>
<p>
Fatal error: Call to undefined function get_called_class() in /in/IDYbW on line 6
Process exited with code 255 . Output for 4.4.2 - 4.4.9 Parse error: syntax error, unexpected T_CLASS in /in/IDYbW on line 2
Process exited with code 255 . Output for 4.3.0 - 4.3.1 , 4.3.5 - 4.3.11 , 4.4.0 - 4.4.1 Parse error: parse error, unexpected T_CLASS in /in/IDYbW on line 2
Process exited with code 255 . Output for 4.3.2 - 4.3.4 Parse error: parse error in /in/IDYbW on line 2
Process exited with code 255 . preferences:dark mode live preview
261.01 ms | 401 KiB | 327 Q