Exemplo n.º 1
0
def loadOrderFromTextFile(filename):
    order = Order()
    txtfile = open(filename, 'r')
    sandwichstrings = txtfile.readlines()
    for sandwichstring in sandwichstrings:
        sandwichstring = sandwichstring[0:-1]
        print(sandwichstring)
        sandwichvars = json.loads(sandwichstring)
        sandwich = Sandwich(sandwichvars['name'])
        if (sandwichvars['bread'] != None):
            sandwich.setBread(sandwichvars['bread'])
        if (sandwichvars['cheese'] != None):
            sandwich.setCheese(sandwichvars['cheese'])
        if (sandwichvars['meat'] != None):
            sandwich.setMeat(sandwichvars['meat'])
        if (sandwichvars['condiments'] != None):
            for condiment in sandwichvars['condiments']:
                sandwich.addCondiment(condiment)
        if (sandwichvars['toasted'] != None):
            sandwich.setToasted(sandwichvars['toasted'])
        order.addSandwich(sandwich)
    return order
Exemplo n.º 2
0
if __name__ == "__main__":
    s1 = Sandwich("Joe")
    s1.setMeat("steak")
    s1.addCondiment("Lettuce")
    print(s1)

    s2 = Sandwich("Mary")
    s2.setCheese("cheddar")
    s2.addCondiment("Mayo")
    print(s2)

    print("Order 1:")
    order = Order()
    print(order)
    order.addSandwich(s1)
    print(order)
    print("Total Price:" + str(order.price()))
    order.addSandwich(s2)
    print(order)
    print("Total Price:" + str(order.price()))

    s3 = Sandwich("Gary")
    s3.setBread("Sourdough")
    s3.addCondiment("Horseradish")
    s3.setToasted(True)
    print("Order 2:")
    order2 = Order()
    order2.addSandwich(s1)
    order2.addSandwich(s2)
    order2.addSandwich(s3)
Exemplo n.º 3
0
    myDict[attr] = value

createFile(myDict)

# 1st Order, 2nd sandwich
s2 = Sandwich("Mary")
s2.setCheese("cheddar")
s2.addCondiment("Mayo")
print(s2)

order1 = Order()
try:
    print(order1)
except ValueError:
    print('No sandwiches in the order.')
order1.addSandwich(s1)

print("Total Price:" + str(order1.price()))
order1.addSandwich(s2)
print(order1)
print("Total Price:" + str(order1.price()))

print('\n----------------------------------------------')

############################
# Test data by creating another order
print('Test data by creating another order:')
order2 = Order()
try:
    print(order2)
except ValueError: