Hi guys, I been working on a project that involves in managing a phone inventory for a company.
So for this project we are to use classes. For the most part I got everything except two areas of
code that I am having trouble with. I have two classes, Class Phone and Class Store.
In the class Store, where it has the method def removePhone,
when the user says yes, the counter should minus one. When the user says no, the counter should
not minus one. Instead, the counter is still subtracting even if the user input is "no".
Any ideas to fix that?
Actually The most important part I am having trouble with is not getting is the def update_phone_info(self) method, which is the
last one in the class Store. Here the user has 5 options to choose from. So if they choose one,
it should do only one and ignore the other 4. The problem is that it's still doing those other
4 no matter what. I was thinking can I use "and" or something like that as a boolean but I don't know
if that will work? If anyone has any suggestions, it would be a great help. I put the whole program so if need be, can be understood from it and have bold the area
of code that is of importance.
# this is the first class
class Phone:
# this is the constructor
def __init__(self, manufacturer, model, retail, quantity):
self.manufact = manufacturer
self.model = model
self.retail_price = retail
self.quantity = quantity
# these next 4 are my mutators:
def set_manufact(self, manufacturer):
self.manufact = manufacturer
def set_model(self,model):
self.model = model
def set_retail_price(self,retail):
self.retail = retail
def set_quantity(self, quantity):
self.quantity = quantity
#-------------------------------------------------------------------
# these next 4 are the accessors:
def get_manufact(self):
return self.manufact
def get_model(self):
return self.model
def get_retail_price(self):
return self.retail_price
def get_quantity(self):
return self.quantity
#------------------------------------------------------------------
# this is the 2nd class, a class for Store
# using as inheritance by putting Phone inside paranthesis.
class Store(Phone):
# this is the constructor
def __init__(self, manufacturer, model, retail, quantity):
self.phones = []
self.number_of_phones = 0
Phone.__init__(self, manufacturer, model, retail, quantity)
# adds phone to store inventory
# add phone to inventory if not in or if it is in inventory.
def addPhone(self):
if Phone not in self.phones:
self.phones.append(Phone)
self.number_of_phones += 1
else:
self.number_of_phones += 1
[B] [I]# removes phone from the store inventory
def removePhone(self):
y=1
n=0
a=input('are you sure you want to delete this phone y or n >>')
if y:
print(self.manufact,self.model,self.retail_price)
self.number_of_phones -= 1
else:
pass[/I][/B]
# to return the amount of phones
def get_number_of_phones(self):
return self.number_of_phones
[B] [I]def update_phone_info(self):
print("Please choose an option to update.")
print('[1] manufacturer')
print('[2] model')
print('[3] retail')
print('[4] quantitiy')
print('[5] EXIT ')
user_choice=input('>')[/B]
x=1
y=2
z=3
w=4
v=5
x=input(str('enter new manufacturer'))
self.manufact=x
y=input(str("enter new model"))
self.model=y
z=input(str('enter adjusted retail price'))
self.retail_price=z
w=input(str("enter the quantity wanted"))
self.quantity=w
v=print ('thank you goodbye')
pass[/I][/B]