Object-oriented programming · 16 / 26 Exercise Easy

Creating Classes and Objects

Objective

Create a class called Person with the attributes name (text), age (integer) and address (text).

Instructions

  • Add a constructor to initialize the attributes.
  • Implement the method display_information(), which displays the name, age and address of the person.
  • Implement the method modify_address(), which changes the address of the person and displays a message confirming the change.
  • Create at least two objects of the Person class with different data.
  • Use display_information() and modify_address() to show the information of the people and to change the address of one of them.

Input and output format. Read, one per line and with no prompts, the name, age and address of the first person, the name, age and address of the second person, and the new address of the first one. Print Information of Person 1: and its data (Name: …, Age: …, Address: …), an empty line, Information of Person 2: and its data, an empty line, then change the address of the first person (printing The address has been modified to: …) and display its information again.

Input
John
30
Street A
Mary
25
Street B
Street C
Output
Information of Person 1:
Name: John
Age: 30
Address: Street A

Information of Person 2:
Name: Mary
Age: 25
Address: Street B

The address has been modified to: Street C
Name: John
Age: 30
Address: Street C

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise