Concept

What does the completed PHP Student class look like?

ComputerScienceOne / Example

"We present the full and completed Student class in Code Sample 45.1.\n\n1 <?php\n\n2 class Student {\n\n3\n\n4 private $firstName;\n\n5 private $lastName;\n\n6 private $id;\n\n7 private $gpa;\n\n8 private $dateOfBirth;\n\n9 private $schedule;\n\n10\n\n11 public function __construct($firstName, $lastName, $id = 0, $gpa = 0.0,\n\n12 $dateOfBirth = null, $schedule = array()) {\n\n13 $this->firstName = $firstName;\n\n14 $this->lastName = $lastName;\n\n15 $this->id = $id;\n\n16 $this->gpa = $gpa;\n\n17 $this->dateOfBirth = new DateTime($dateOfBirth);\n\n18 $this->schedule = $schedule;\n\n19 }\n\n20\n\n21 public function __toString() {\n\n22 return $this->getFormattedName() . \" born \" .\n\n23 $this->dateOfBirth->format(\"Y-m-d\");\n\n24 }\n\n25\n\n26 /**\n\n27 * Returns a formatted String of the Student's\n\n28 * name as Last, First.\n\n29 */\n\n30 public function getFormattedName() {\n\n31 return $this->lastName . \", \" . $this->firstName;\n\n32 }\n\n33\n\n34 /**\n\n35 * Scales the GPA, which is assumed to be on a\n\n36 * 4.0 scale to a percentage.\n\n37 */\n\n38 public function getGpaAsPercentage() {\n\n39 return $this->gpa / 4.0;\n\n40 }\n\n41\n\n42 public function getFirstName() {\n\n43 return $this->firstName;\n\n44 }\n\n45\n\n46 public function getLastName() {\n\n47 return $this->lastName;\n\n48 }\n\n49\n\n50 public function getId() {\n\n51 return $this->id;\n\n52 }\n\n53\n\n54 public function getGpa() {\n\n55 return $this->gpa;\n\n56 }\n\n57\n\n58 public function addCourse($c) {\n\n59 $this->schedule[] = $c;\n\n60 }\n\n61\n\n62 }\n\n63\n\n64 ?>\n\nCode Sample 45.1.: The completed PHP Student class."

Related Ideas

What does the completed PHP Student class look like? | ComputerScienceOne | Bifalgorithm | Bifalgorithm