Age of Teacher and Students

Learn about inheritance, method overriding, and instance variables in Ruby and apply these concepts to solve a problem.

Problem

A school consists of teachers and students, and students are grouped by grades. Implement the Teacher and Student classes with age method to calculate the age from the date of birth. Use the concept of inheritance to improve code reusability.

Also, write the following methods:

  • teacher_avg_age that takes an array of teacher objects and returns their average age.

  • student_avg_age that takes two parameters—an array of student objects and a grade—and returns the average age of students grouped by the specified grade.

Input data

Get hands-on with 1400+ tech skills courses.