Exercise 2: Using a Module
Learn to define and include a module in different classes.
We'll cover the following
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
andTeacher
through theinitialize()
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 theFormatter
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 offirst_name
andlast_name
and combines the two. -
format_phone
: This method takes a phone number stored as a string and removes its hyphens.
Try it yourself
# Start your code here