IN PYTHON PLEASE The Acme Retail Warehouses has 2 warehouses in the city. Wareho
ID: 3593280 • Letter: I
Question
IN PYTHON PLEASE
The Acme Retail Warehouses has 2 warehouses in the city.
Warehouse 1 holds hardware material that are distributed to stores.
Warehouse 2 holds grocery items that are distributed to grocery stores.
You need to create 2 classes.
The first class is the warehouse.
It has attributes Location (street address you give it), type of storage (hardware or grocery), and a list of inventory items (objects of the second class discussed below).
The class should contain accessors and mutators as well as an __str__.
The second class is inventory.
It has attributes ID, Description, Quantity, Cost. The class should contain accessors, mutators, an __str__, and a method to calculate and return the retail price. All items have a 20% markup.You need to write 2 programs. Program 1 reads data from 2 files.
hardware.txt contains hardware items that are stored in Warehouse 1. The data are comma delimited and contain the following fields: ID number, Description, Quantity, Cost. grocery.txt contains grocery items that are stored in Warehouse 2. The data are comma delimited and contain the following fields: ID number, Description, Quantity, Cost.
For each file, create a warehouse object.
You supply the location and type of storage for each object.
Use the data from the files to create the inventory object list.
Both files should be saved using the Pickle module.Program 2 is a menu driven program.
The user should be asked which warehouse they will be working with and then a menu should be displayed with the following choices:
1. Add Item – allows the user to add an item to the inventory (you supply the data)
2. Delete Item – allows the user to delete an item from the inventory (returns the information)
3. Change quantity – allows the user to add or subtract from the inventory
4. Change price – allows the user to change the price of an item in the inventory
5. Print item – the user would enter an ID and the program will display the inventory information for that ID
6. Quit
IN PYTHON PLEASE
Explanation / Answer
I am using pythn v2.7 .. If you are using python 3.0 then the syntax of the program can change but the logic remains the same.
PROGRAM : 1
#!/usr/bin/python
import os;
class inventory:
def __init__(self):
self.id = -1;
self.description = "";
self.quantity = 0.0;
self.cost = 0.0;
def setId(self,id1):
self.id = id1;
def setDescription(self,desc):
self.description = desc;
def setQuantity(self,qty):
self.quantity = qty;
def setCost(self,cost):
self.cost = cost;
def getId(self):
return self.id;
def getDescription(self):
return self.description;
def getQuantity(self):
return self.quantity;
def getCost(self):
return self.cost;
def __str__(self):
return "Id : " + str(self.id) + " Description : " + self.description + " Quantity : " + str(self.quantity) + " Cost : " + str(self.cost);
def getRetailPrice(self):
price = cost + (0.2*cost);
return price;
class warehouse:
def __init__(self):
self.location = "";
self.invType = "";
self.invList = list();
def setLocation(self,loc):
self.location = loc;
def setInvType(self,invType):
self.invType = invType;
def setInvList(self,invList):
self.invList = invList;
def getLocation(self):
return self.location;
def getInvType(self):
return self.invType;
def getInvList(self):
return self.invList;
def __str__(self):
str1 = ""
for ob in self.invList:
str1 = str1 + str(ob) + " "
return "Location : <" + self.location + "> Type : <" + self.invType + "> List : " + str1;
def readFile(filename,location):
os.path.exists(filename)
fileob = open(filename, "r")
str1 = fileob.read()
lines = str1.split(" ")
ware = warehouse()
ware.setLocation(location);
if filename == "hardware.txt":
ware.setInvType("hardware")
else:
ware.setInvType("grocery.txt")
l = []
for value in lines:
if not value:
break
info = value.split(",")
inv = inventory()
inv.setId(info[0])
inv.setDescription(info[1])
inv.setQuantity(info[2])
inv.setCost(info[3])
l.append(inv);
ware.setInvList(l)
return ware
#Creating warehouse1
warehouse1 = readFile("hardware.txt","Atlanta");
#Creating warehouse2
warehouse2 = readFile("grocery.txt","Texas");
print warehouse1
print warehouse2
PROGRAM 2 :
#!/usr/bin/python
import os;
class inventory:
def __init__(self):
self.id = -1;
self.description = "";
self.quantity = 0.0;
self.cost = 0.0;
def setId(self,id1):
self.id = id1;
def setDescription(self,desc):
self.description = desc;
def setQuantity(self,qty):
self.quantity = qty;
def setCost(self,cost):
self.cost = cost;
def getId(self):
return self.id;
def getDescription(self):
return self.description;
def getQuantity(self):
return self.quantity;
def getCost(self):
return self.cost;
def __str__(self):
return "Id : " + str(self.id) + " Description : " + self.description + " Quantity : " + str(self.quantity) + " Cost : " + str(self.cost);
def getRetailPrice(self):
price = cost + (0.2*cost);
return price;
class warehouse:
def __init__(self):
self.location = "";
self.invType = "";
self.invList = list();
def setLocation(self,loc):
self.location = loc;
def setInvType(self,invType):
self.invType = invType;
def setInvList(self,invList):
self.invList = invList;
def getLocation(self):
return self.location;
def getInvType(self):
return self.invType;
def getInvList(self):
return self.invList;
def __str__(self):
str1 = ""
for ob in self.invList:
str1 = str1 + str(ob) + " "
return "Location : <" + self.location + "> Type : <" + self.invType + "> List : " + str1;
option = raw_input("Enter the type of warehouse to be created : 1)Hardware 2)Grocery : ");
ware = warehouse()
ware.setLocation("Atlanta")
ware.setInvType(option);
option = 1
while option != 6:
menu = "1.Add an item to the list " + "2.Delete an item " + "3.Change quantity of an item " + "4.Change price of an item " + "5.Print an item " + "6.Exit "
print "Choose your action : "
option = int(raw_input(menu));
if option == 1:
inv = inventory()
inv.setId(int(raw_input("Enter the Id of the product : ")))
inv.setDescription(raw_input("Enter the product description : "))
inv.setQuantity(float(raw_input("Enter the quantity : ")))
inv.setCost(float(raw_input("Enter the cost : ")))
l = ware.getInvList()
l.append(inv);
elif option == 2:
id1 = int(raw_input("Enter the id of the item : "))
l = ware.getInvList()
i = 0
for ob in l:
if ob.getId() == id1:
break;
i = i + 1;
ob = l.pop(i)
print "Object deleted : " + str(ob)
elif option == 3:
id1 = int(raw_input("Enter the id of the item whose quantity needs to be changed :"))
qty = float(raw_input("Enter the quantity : "))
l = ware.getInvList()
i = 0
for ob in l:
if ob.getId() == id1:
break;
i = i + 1;
l[i].setQuantity(qty);
elif option == 4:
id1 = int(raw_input("Enter the id of the item whose cost needs to be changed :"))
cost = float(raw_input("Enter the new cost : "))
l = ware.getInvList()
i = 0
for ob in l:
if ob.getId() == id1:
break;
i = i + 1;
l[i].setCost(cost);
elif option == 5:
id1 = int(raw_input("Enter the id of the item whose cost needs to be changed :"))
l = ware.getInvList()
i = 0
for ob in l:
if ob.getId() == id1:
break;
i = i + 1;
print ob
else:
print "Bye"