HEEEEELLLLLLP!!!!

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.

Thankyou

import time
 
def timestamp():
    lt = time.localtime(time.time())
    return "%02d.%02d.%04d " % (lt[0], lt[1], lt[2])
 
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()

Recommended Answers

All 5 Replies

ord is built in function to find numeric value of character, please rename the object instance.

Why there is this order instance in class level common to all orders?

Looks like you are replacing old orders every time new order is made, but then how do you know about earlier orders?

i don't know why i have it how it is, i'm only a beginner and havin a hell of a time gettin anything to work! pls assist?

You don't create a class by listing it's methods as variables!

Also you are overriding methods to their parameter.Your init does not adhere to assignment. Define status state variable in init. Methods should start with checking of timestamp and prerequisits raising the exception if necessary.

Think this is a school assignments,and your try now is really a mess.
You should look more at how class in python work,read some tutorials/book or ask your teacher for help.

Create an Order class. The Order class should have a constructor which takes 2 parameters: a tracking number and a timestamp.

def __init__(self, tracker, timer, pay, ship, complete, cancel):
You have 6 parameters,for the constructor.
And you have to set variabels for the constructor.
self.tracker = tracker
self.timer = timer

So it should look like this.

def __init__(self, tracker, timer):
     '''This is the constructor we give it 2 arguments'''
     self.tracker = tracker
     self.timer = timer

Some code not finish off course,that can lead you in a better direction for solving this assignments.

import time

class Order(object):
    def __init__(self, tracker, time):
        '''This is the constructor we give it 2 arguments'''
        self.tracker = tracker
        self.timer= time
   
    #Implement 4 methods (pay, ship, complete, cancel)
    def pay(self,payment):
        '''This is a method that belong to Order class'''
        self.payment = payment
        self.payment_timer= self.timer        
    
    def ship(self,timestamp):        
        pass
    
    def complete(self):        
        pass
    
    def cancel(self):        
        pass   
   
    def __str__(self):
        '''Return a pleasant representation'''
        return "tracking_number %s payment %.2f payment_timer %s" % (self.tracker, self.payment,self.payment_timer)    

def timestamp():    
    lt = time.localtime(time.time())
    return "%02d.%02d.%02d.%02d.%02d" % (lt[0], lt[1], lt[2], lt[3], lt[4])
    
def main():   
    tracking_number = 44    
    #Example of making objects using Order class
    #We have to give 2 arguments to the constructor 
    object_order_1 = Order(tracking_number, timestamp())
    
    #Then we can test out the new object
    payment = float(raw_input('Pay money: '))    
    object_order_1.pay(payment)
    
    #Because off __str__ we can print out object_order_1
    print object_order_1    
  
if __name__ == "__main__":
    main()

'''-->Out
Pay money: 5000.50
tracking_number 44 payment 5000.50 payment_timer 2010.05.24.17.17
'''
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.