Answer:
Code is in the attached screenshot.
Step-by-step explanation:
Assumed it was written in Java based on your other question asked.
3.7m questions
4.8m answers