48.3k views
1 vote
Create an abstract Student class for Parker University. The class contains fields for student ID number, last name, and annual tuition. Include a constructor that requires parameters for the ID number and name. Include get and set methods for each field; the setTuition() method is abstract. Create three Student subclasses named UndergraduateStudent, GraduateStudent, and StudentAtLarge, each with a unique setTuition() method. Tuition for an UndergraduateStudent is $4,000 per semester, tuition for a GraduateStudent is $6,000 per semester, and tuition for a StudentAtLarge is $2,000 per semester.

User Jbarreiros
by
4.5k points

1 Answer

3 votes

Answer:

<?php

abstract class Student {

public $Id; // field for student ID Number

public $Lastname; // field for student last name

public $Tuition; // field for annual tuition

public function __construct( $id, $lastname) { // constructor property to initialise id number and lastname

$this->Id = $id; // variable initialisation

$this->Lastname = $lastname;

}

// set Id number

public function setId($id) {

return $this->Id = $id;

}

// get id number

public function getId() {

return $this->Id;

}

// set lastname

public function setLastname($lastname) {

return $this->Lastname = $lastname;

}

// get lastname

public function getLastname() {

return $this->Lastname;

}

//the setTuition() method is abstract

abstract public function setTuition($amount);

// get Tuition fee

public function getTuition(){

return $this->Tuition;

}

}

// UndergraduateStudent is a subclass that inherits the properties of class Student

class UndergraduateStudent extends Student {

public function setTuition($amount) {

return $this->Tuition = $amount;

}

}

class GraduateStudent extends Student {

public function setTuition($amount) {

return $this->Tuition = $amount;

}

}

class StudentAtLarge extends Student{

public function setTuition($amount) {

return $this->Tuition = $amount;

}

}

// create an instance of the class

$Undergraduate = new UndergraduateStudent(1,"Anyadike");

// call all required methods

echo '<span> id: </span>'.$Undergraduate->getId();

echo '<span> name:</span>'.$Undergraduate->getLastname();

echo "<span> Tution:</span>".$Undergraduate->setTuition("$4000");

echo "<br>";

$GraduateStudent = new GraduateStudent(2,"Okonkwo");

echo '<span> id: </span>'.$GraduateStudent->getId();

echo '<span> name:</span>'.$GraduateStudent->getLastname();

echo "<span> Tution:</span>".$GraduateStudent->setTuition("$6000");

echo "<br>";

$StudentAtLarge = new StudentAtLarge(3,"Ojukwu");

echo '<span> id: </span>'.$StudentAtLarge->getId();

echo '<span> name:</span>'.$StudentAtLarge->getLastname();

echo "<span> Tution:</span>".$StudentAtLarge->setTuition("$2000");

?>

Step-by-step explanation:

explanations are detailed in the comment (//)

User Romuloux
by
4.9k points