Question: 5 . Creating the Order Class python code 0 . Create a new module my _ order.py 1 . Create a New Class Order: Define

5. Creating the Order Class python code
0. Create a new module my_order.py
1. Create a New Class Order:
Define a class named Order in Python.
2. Global Private Variable:
Inside the class, create a global private variable called __number_of_orders to track the total number of
orders.
This variable should be incremented each time a new order is created.
3. Private Internal Variables:
Add two private instance variables:
__name (to store the name of the order).
__price (to store the price of the order).
These variables should only be accessible and modifiable through getter and setter methods.
4. Define Getter and Setter Methods:
Write a getter method get_name() that returns the value of the private variable __name.
Write a setter method set_name() that allows you to set or modify the value of __name.
Similarly, write a getter method get_price() that returns the value of the private variable __price.
Write a setter method set_price() that allows you to set or modify the value of __price.
5. Create a display_info() Function:
Add a method called display_info() that prints the name and price of the order.
Ensure that the price is displayed with two decimal places (e.g., $4.50).
6. Track the Number of Orders:
Write a class method get_number_of_orders() to return the value of __number_of_orders, which tracks
the total number of orders processed.
Each time a new Order object is created, increment __number_of_orders.
7. Test the Class:
After writing the class, create a few Order objects and test all the methods ( use this code below to test
it)

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!