Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can someone help with this PHP assignment? Thank you!!! Vehicle Class (Abstract)

ID: 3908838 • Letter: C

Question

Can someone help with this PHP assignment? Thank you!!!

Vehicle Class (Abstract)

Create an abstract class called Vehicle with the following fields and abstract methods:

Fields:  engineState, speed, engineSize, vehicleType

Create setters and getters for these fields.

Create the following abstract methods: startEngine, stopEngine, accelerate, break, showInfo

Car, Plane, Boat Classes (Concrete)

Create standard classes for Car, Plane, Boat that extend the Vehicle class.

Implement all the methods accordingly. (i.e. check if the engine is already ON when a start() method is invoked).

Scooter example:

public start(){
if ($this->engineState != "ON") {
$this->engineState = "ON";
echo "Starting " . $this->getVehicleType() . " engine...";
} else {
echo "Engine is already ON";
}

public accelerate($newSpeed){
$this->setSpeed($newSpeed);
}

HTML Page

Create an HTML page called vehicle.php

Include the classes into the web page

Instantiate three objects (one of each class) and initialize their properties.

Display all information to the browser.

Separate these classes from the Web page.

Explanation / Answer

Hello there,

I have completed your assignment as per given instructions.

Save following source code in a file:

==>class.php

<?php
error_reporting(1);

//////////////////////////////////////////////////////////////
abstract class Vehicle
{
protected $engineState;
protected $speed;
protected $engineSize;
protected $vehicleType;

abstract protected function startEngine();
abstract protected function stopEngine();
abstract protected function accelerate($newSpeed);
abstract protected function break($newSpeed);
abstract protected function showInfo();

protected function getVehicleType() {
      return $this->vehicleType;
}

protected function setSpeed($newSpeed) {
      $this->speed=$newSpeed;
}

}

////////////////////////////////////////////////////////


class Car extends Vehicle
{

    public function __construct($engineSize,$vehicleType) {
        $this->engineState="OFF";
        $this->speed=0;
        $this->engineSize=$engineSize;
        $this->vehicleType=$vehicleType;
    }
      

   public function startEngine() {

        if($this->engineState != "ON") {
                 $this->engineState="ON";
               echo "Starting ". $this->getVehicleType(). " engine...<br>";
        }
       else {
               echo "Engine is already ON<br>";
        }
   }  


   public function stopEngine() {
      
        if($this->engineState == "ON"){
                $this->engineState="OFF";
               echo "Stopping ". $this->getVehicleType(). " engine...<br>";
        }
      
        else {
               echo "Engine is already Off<br>";
        }
   }         


   public function break($newSpeed) {
       $this->setSpeed($newSpeed);
   }
      
      
   public function accelerate($newSpeed){
        $this->setSpeed($newSpeed);
   }


    public function showInfo() {
        echo "Vehicle Type: ".$this->vehicleType."<br>";
        echo "Engine Size: ".$this->engineSize."<br>";
        echo "Engine State: ".$this->engineState."<br>";
        echo "Current Speed: ".$this->speed."<br>";
    }

}


////////////////////////////////////////////////////////


class Plane extends Vehicle
{

    public function __construct($engineSize,$vehicleType) {
        $this->engineState="OFF";
        $this->speed=0;
        $this->engineSize=$engineSize;
        $this->vehicleType=$vehicleType;
    }
      

   public function startEngine() {

        if($this->engineState != "ON") {
                 $this->engineState="ON";
               echo "Starting ". $this->getVehicleType(). " engine...<br>";
        }
       else {
               echo "Engine is already ON<br>";
        }
   }  


   public function stopEngine() {
      
        if($this->engineState == "ON"){
                $this->engineState="OFF";
               echo "Stopping ". $this->getVehicleType(). " engine...<br>";
        }
      
        else {
               echo "Engine is already OFF<br>";
        }
   }         


   public function break($newSpeed) {
       $this->setSpeed($newSpeed);
   }
      
      
   public function accelerate($newSpeed){
        $this->setSpeed($newSpeed);
   }


    public function showInfo() {
        echo "Vehicle Type: ".$this->vehicleType."<br>";
        echo "Engine Size: ".$this->engineSize."<br>";
        echo "Engine State: ".$this->engineState."<br>";
        echo "Current Speed: ".$this->speed."<br>";
    }

}
////////////////////////////////////////////////////////


class Boat extends Vehicle
{

    public function __construct($engineSize,$vehicleType) {
        $this->engineState="OFF";
        $this->speed=0;
        $this->engineSize=$engineSize;
        $this->vehicleType=$vehicleType;
    }
      

   public function startEngine() {

        if($this->engineState != "ON") {
                 $this->engineState="ON";
               echo "Starting ". $this->getVehicleType(). " engine...<br>";
        }
       else {
               echo "Engine is already ON<br>";
        }
   }  


   public function stopEngine() {
      
        if($this->engineState == "ON"){
                $this->engineState="OFF";
               echo "Stopping ". $this->getVehicleType(). " engine...<br>";
        }
      
        else {
               echo "Engine is already Off<br>";
        }
   }         


   public function break($newSpeed) {
       $this->setSpeed($newSpeed);
   }
      
      
   public function accelerate($newSpeed){
        $this->setSpeed($newSpeed);
   }


    public function showInfo() {
        echo "Vehicle Type: ".$this->vehicleType."<br>";
        echo "Engine Size: ".$this->engineSize."<br>";
        echo "Engine State: ".$this->engineState."<br>";
        echo "Current Speed: ".$this->speed."<br>";
    }

}

?>

/////////////////////////////////////////////////////////////////////////////////////////////////////////

I have imported above php script in file named vehicle.php and it is as follows:

==> vehicle.php

<html>
<body>
<font color="green" size="5">
<?php

include("class.php");

$carObj = new Car("1.2L","CAR");
$carObj->startEngine();
$carObj->accelerate(40);
$carObj->showInfo();
$carObj->stopEngine();

echo "<br><br>";

$planeObj = new Car("20L","PLANE");
$planeObj->startEngine();
$planeObj->accelerate(400);
$planeObj->showInfo();
$planeObj->stopEngine();

echo "<br><br>";

$boatObj = new Car("2L","BOAT");
$boatObj->startEngine();
$boatObj->accelerate(150);
$boatObj->showInfo();
$boatObj->stopEngine();


?>

</font>
</body>
</html>

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Don't hesitate to ask querries and updates in above solution,I am here to help you!!!

Thank you!!!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote