Question: 6 0 . 0 0 Step 4 . Create new module named order.py 1 . Import the Person Class into the order.py module Before you

60.00
Step 4. Create new module named order.py
1. Import the Person Class into the order.py module
Before you start writing the Order class, youll need to import the Person class from another
file or module where it is defined. This is necessary because we will use a Person object as
the owner of the order
import person
2. Define the Order Class and a Class Variable
Create a class named Order.
Inside the class, define a class variable order_count and set it to 0. This variable will
track the total number of orders created.
3. Define the Constructor (__init__ Method)
Inside the class, define the __init__ method. This is the constructor, which gets called
automatically whenever a new Order object is created.
The constructor should accept three parameters:
price: the price of the order.
name: the name of the order.
owner: a Person object that represents the owner of the order.
Inside the constructor:
Increment the order_count class variable by 1 each time a new order is created.
Store the price and name as private instance variables (use double underscores like
__price and __name).
Store the owner as an instance variable _owner (it doesnt need to be private but
should be managed carefully).
4. Write Getter and Setter Methods for price
Write a get_price() method that returns the value of __price.
Write a set_price(price) method that updates the value of __price.
5. Write Getter and Setter Methods for name
Write a get_name() method that returns the value of __name.
Write a set_name(name) method that updates the value of __name.
6. Write the displayInfo() Method
Write a method called displayInfo() to display information about the order.
Inside this method:
Print a separator line to make the output clearer.
Print the name and price of the order.
Call the displayInfo() method of the owner (the Person object) to display the persons
information. You can use self._owner.displayInfo() to access the persons info.
Output should look like this:
========================================
DisplayInfo Order
========================================
Name: Coffee
Name: 19.99
----------------------------------------
name: Albert Einstein money: $ 100.00
7. Define the main() Function
Write a main() function that will be executed when the program runs.
Inside the main() function:
Create a Person object (using the Person class from the person module). You will use
this person as the owner of the order.
Create an Order object, passing the price, name, and the Person object (owner) to the
constructor.
Call the displayInfo() method of the Order object to display the order and owner details.
8. Ensure the Program Runs Correctly
At the bottom of your file, add the standard Python entry point:
if __name__=="__main__":
main()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!