Working on an assignment and don’t know where I am going wrong. Here is the assignment.
/* Step 1:
- To get stated with this assignment, first create a new class called “Student”.
- Inside your class, create a public variable called $grades.
- Then create a private variable called $average.
- Additionally, create a public method called CreateAverage().
- Inside your method, you’ll set your $average attribute to equal the following formula:
- array_sum($this->grades) / count($this->grades)
- Now, inside your CreateAverage method, return the value of the $average attribute
Note: You wont need to change the class you created in Step 1 beyond this point.
*
- Now that you have created your class and its method, I’d like you to
- instantiate your class inside a variable called $jack.
- Now, I’d like you to set the value of jack’s $grades attribute
- to the following array of grades: array(98,95,85,79,90,92,91).
- Remember that we are setting this attribute value outside of the class.
- Now that you’ve set the grades for this student,
- you can call the CreateAverage() method.
- To output the method’s calculations,
- you’ll need to echo the method since it returns a value.
- Hint: Your final output for this assignment should be “90”.
Here is what I have so far:
[php]