Question: 5 . Creating the Order Class python code 0 . Create a new module my _ order.py 1 . Create a New Class Order: Define
Creating the Order Class python code
Create a new module myorder.py
Create a New Class Order:
Define a class named Order in Python.
Global Private Variable:
Inside the class, create a global private variable called numberoforders to track the total number of
orders.
This variable should be incremented each time a new order is created.
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.
Define Getter and Setter Methods:
Write a getter method getname that returns the value of the private variable name.
Write a setter method setname that allows you to set or modify the value of name.
Similarly, write a getter method getprice that returns the value of the private variable price.
Write a setter method setprice that allows you to set or modify the value of price.
Create a displayinfo Function:
Add a method called displayinfo that prints the name and price of the order.
Ensure that the price is displayed with two decimal places eg $
Track the Number of Orders:
Write a class method getnumberoforders to return the value of numberoforders, which tracks
the total number of orders processed.
Each time a new Order object is created, increment numberoforders.
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
