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