In: Computer Science
1. PHP OOP
Create a complete PHP enabled website that defines and uses a PineApple class in PHP. The class has following members.
Properties
$color: string type
$taste: string type
$weight: number type
Standard constructor, with 3 parameters
Member functions
eat(): no return, no parameter, print a short paragraph in English to describe
how to eat a pineapple.
grow(): no return, no parameter, print a short paragraph in English to describe how to grow a pineapple plant.
display(): no return, no parameter, print the name and current value of every property of this class.
In the primary PHP script, create two objects from the PineApple class. Then call every member function form each object in an appropriate manner.
2. JavaScript OOP
Write a complete webpage with embedded JavaScript code that defines a bunny object that is made of following properties and methods.
Property color: string type
Property earLength: number type
Property furType: string type
Method toPrint(): print out the name and value of every property of this current object
Method run(): print out the procedure that describes how this bunny swims.
In details, do the following
Create a bunny object using object literal.
Define the constructor function of bunny and create another bunny object using this constructor and the new keyword.
Read three property values from the keyboard with proper prompt for every object created above.
For each object, call its every method.
Please try to divide multiple questions to seperate individual
questions. Here is the code for the first one. PHP:
------
<?php
class PineApple{
var $color;
var $taste;
var $weight;
function __construct($c, $t, $w){
$this->color = $c;
$this->taste = $t;
$this->weight = $w;
}
function eat(){
echo "<br><br>Cut
PineApple into pieces using a knife or by hand if you like.
Remember to remove outer shell before otherwise it case cause some
serious damage to stomache. Then just eat it bro.";
}
function grow(){
echo "<br><br>Find
PineApple seeds somewhere lying around, I don't know man where you
can find them just buy it on amazon. Then get some water, some
soil, some sunlight and mix them up together. Bamm! you got
PineApple.";
}
function display(){
echo
"<br>Color:".$this->color;
echo
"<br>Taste:".$this->taste;
echo
"<br>Weight:".$this->weight;
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>PineApple</title>
</head>
<body>
<?php
$A = new PineApple("blue", "salty", 23);
$A->grow();
$A->eat();
$A->display();
echo "<hr>";
$B = new PineApple("yellow", "sweet", 11);
$B->grow();
$B->eat();
$B->display();
?>
</body>
</html>
-------
------
Hastebin link in case code lose formatting: http://www.hastebin.com/tefahinato.xml