Here's what I have after hour upon hour of battling away at OOP...
If anyone could fix my errors and help with a bit more of the development I'd be very grateful, I can't wrap my head around OOP despite the hours of reading and trying :(
The task I was posed with is:
-An internet shop requires an order tracking system.
-When someone buys an item online, an Order is created.
-Orders aren't processed until payment has been confirmed.
-Once the order has been processed it can be shipped.
-The order is tracked until it has been delivered, at which point it is recorded as complete. Orders can be cancelled, but only before they are shipped.
Create an Order class. The Order class should have a constructor which takes 2 parameters: a tracking number and a timestamp. Implement 4 methods (pay, ship, complete, cancel). Each method should take 1 timestamp parameter. Also implement the standard "__str__" method to provide convenient a way of printing out the information in an Order.
Make sure the Order adheres to the business rules as outlined above: When Orders are created payment is unconfirmed.
Orders must be paid before any other processing can occur. Orders cannot be shipped unless they are paid. Orders cannot be completed unless they are shipped. Orders cannot be cancelled after they have been shipped. The timestamp for each step in the business process (pay, ship, complete) must be greater than the timestamp for the previous step. Raise an exception if an invalid method call is made – that is if a call is made to a method while the Order is in the wrong state, of if the timestamp supplied in the method is less than or equal to the current timestamp.
As an extension add save/load capabilities.
import time def timestamp(): lt = time.localtime(time.time()) return "%02d.%02d.%04d " % (lt, lt, lt) if __name__ == '__main__': print timestamp() def main(): total = 0 choice = None while choice != '0': print \ ''' Order Tracking System 0 - Quit 1 - New Order 2 - Update Order ''' choice = int(raw_input('Enter choice: ')) print #quit if choice == '0': print 'Bye' break elif choice =='1': total = total + 1 order = Order(total) elif choice =='2': class Order(object): '''order production system''' ord = Order() def __init__(self, tracker, timer, pay, ship, complete, cancel): def tracker(self): return self.tracker def timer(self): self.timer = timestamp() def pay(self, timer): self.pay = pay self.timer = timestamp() def ship(self, timer): self.ship = ship self.timer = timestamp() def complete(self, timer): self.complete = complete self.timer = timestamp() def cancel(self, timer): self.cancel = cancel self.timer = timestamp() def set_pay(self, new_pay): main()