You are writing code to be distributed as part of a set of teaching materials, and you have incorporated within it some third-party code licensed to you under Apache2.
The use of the third-party code makes your program a derivative work of the Apache2 code. Section 4 of the Apache2 licence says you may do this, and places the following conditions on such use:
a. You must give any other recipients of the Work or Derivative Works a copy of this License; and
b. You must cause any modified files to carry prominent notices stating that You changed the files; and
c. You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
d. If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file [...]
Conditions a, c, and d are self-evident, and b will be satisfied if you add your own copyright notice to the file(s) in question - which you should be adding to all the code you write anyway.
If you are unwilling or unable to honour those conditions, then you will need the permission of the original author.
You will also need to decide what licence to place on the derivative work. Life will be simplest if you choose Apache2, since you are distributing a copy of that licence anyway, but you are free to choose something like GPLv3 if you want to.