Exercise 2: Using a Module

Learn to define and include a module in different classes.

Problem statement

Define two classes, Student and Teacher, by including a module called Formatter in both classes.

Task 1:

You’re required to:

  • Populate the class attributes of Student and Teacher through the initialize() method.
  • Define attribute readers for these attributes.

Each of these classes has the attributes:

  • first_name
  • last_name
  • phone_no

And an instance method:

  • print_info: This method uses the methods defined in the Formatter module to print the name and phone number information.

Task 2

The Formatter module includes the following methods:

  • format_name: This method capitalizes only the first letters of first_name and last_name and combines the two.

  • format_phone: This method takes a phone number stored as a string and removes its hyphens.

Try it yourself

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy