Jump to content

Python class help.

Nipplemilk909

#
#
#
class Pizza():
    def __init__(self, brand, size, numT):
        self._brandName=brand
        self._size=size
        self._numTop=numT
        self._price=0
        
    def getBrandName(self):
        return self._brandName
    
    def getSize(self):
        return self._size

    def getTopping(self):
        return self._numTop

    def setBrandName(self,bm):
        self._brandName=bm

    def setSize(self,s):
        self._size=s

    def setTopping(self,t):
        self._numTop=t

    def setPrice(self,p):
        self._price=p
        

    def calculateCost(self):
        
        if self._brandName=="Pizza Hut":
            if self._size=="small":
                self._price=10+(1*self._numTop)
            else:
                self._price=14+(3*self._numTop)
                
                
        else: #dominos
            if self._size=="small":
                self._price=12+(2*self._numTop)
            else:
                self._price=16+(3*self._numTop)
        
        return self._price


    def __str__ (self):
         return self._brandName + "    " + self._size + " " + \
                "pizza " + "   " + "Cost is: " + str (self._price)

class PizzaStore():
    def __init__(self, store, orders):
        self._storeName=store
        self._orderList=orders

    def orderReceived(pizza):
        return self._orderList
    def __str__(self):
        return "has received the following order"
        
    

        
def main():
    p1=Pizza("Pizza Hut","small",3)
    p1.calculateCost()
    print(p1)

    
    p1.setSize("large")
    p1.calculateCost()
    print(p1)

    p2=Pizza("Domino","large",2)
    p2.calculateCost()
    print(p2)
  
    
main()
                

im trying to .....

Create another class named PizzaStore.

The class PizzaStore (sells all kinds of pizza brands) has the following attributes (instance variables):

* Name of the store

* List of pizza orders received.

 

The class has the following methods:

* __init__

* orderReceived (pizza)

* __str__

 

The main section should look like this:

 

p1 = Pizza (“Pizza Hut”, small, 3)

 

p2 = Pizza (“Domino’s”, large, 2)

 

s1 = PizzaStore(“Pizza House”)

 

s1.orderReceived(p1)

s1.orderRecevied(p2)

 

print(s1)

 

The result (output) should look like:

Pizza House has received the following order: small size, 3 toppings, Pizza Huts; large size, 2 toppings, Domino’s

 

 

im lost in creating the order received method and the __str__method 

Link to comment
Share on other sites

Link to post
Share on other sites

Make yourself a list so you can add orders to it, then when it comes to return store object as string iterate over your orders list and build a string. I don't know if your _orderList should be PizzaStore init argument, I would just leave store there (the name) and initialize _orderList with empty list []. Then just append pizza to _orderList on orderReceived and finally enumerate over _orderList in __str__ 

 

BTW: Your post is formatted with black font, so it is black on black for me as I'm using dark forum theme.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×