Bifalgorithm post · Computer science one · Example
What does the completed PHP Student class look like?
What does the completed PHP Student class look like? (Computer science one · Example) — "We present the full and completed Student class in Code Sample 45.1.\n…
Ideas in this flowchart
- The completed PHP Student class
- Private properties store the first name, last name, ID, GPA, date of birth, and schedule.
- The constructor accepts student data and initializes the object.
- Optional parameters default the ID and GPA to 0, the date of birth to null, and the schedule to an empty array.
- The constructor converts the date of birth to a DateTime object and stores the schedule.
- __toString() returns the formatted name followed by the birth date in Y-m-d format.
- getFormattedName() returns the student's name as Last, First.
- getGpaAsPercentage() scales the GPA from a 4.0 scale to a percentage.
- Getter methods expose the first name, last name, ID, and GPA.
- addCourse($c) appends a course to the student's schedule.