please help me. I need same output. Create a Python project for the following pr
ID: 3829084 • Letter: P
Question
please help me. I need same output. Create a Python project for the following problem. Zip the Python project into a zip file. Submit the zip file to Blackboard for credit.
In Lab 12 you wrote a program for Wake-Mart customers to check out grocery items. Now Wake-Mart wants an upgrade of the system. First, they want the customer to register before ordering items. They only accept payment by credit card or debit card now. The customer must enter card information during the registration process. Second, instead of asking the customer to enter the price of each item and the value of each coupon, now they want the customer to enter a 4-digit code for each item and each coupon, and the program will look up the price from a price list or the value of the coupon from a coupon list. The following lists the requirements of this project.
Define a Customer class. The following class diagram shows the design of this class:
This class has 5 private instance variables to store customer name, credit card number, credit card security code, debit card number, and debit card PIN. It has 6 methods. The constructor receives customer name as an argument and stores it in an instance variable. It should also create the other instance variables and initialize them all to empty strings.
In the inputCardInfo method, the user enters credit card number, credit card security code, debit card number and debit card PIN. All these input values should be stored in instance variables.
The goal of the verifyCreditCard method is to check whether the security code is correct. This method is called when the user chooses to pay by credit card. It compares the security code entered by the user during check out against the security code stored in the Customer object. If they are the same, this method returns True. Otherwise, it returns False.
The verifyDebitCard method is similar. It compares the PIN entered by the user during check out against the PIN stored in the Customer object. If they are the same, this method returns True. Otherwise, it returns False.
The creditCradLastFour method returns the last four digits of the credit card number, while the debitCardLastFour returns the last four digits of the debit card number.
The main module of the project must have the following six functions.
In the main function, ask the customer to enter his name. Use it to create a Customer object. Call the inputCardsInfo method of the object to input credit card and debit card information. Call the scanPrices function and the scanCoupons function for the customer to order items and enter coupons. These functions return the total price of the items and the total value of the coupons. Use these return values to calculate how much the customer needs to pay. Display this amount on the screen. Call the makePayment method to process payment. Pass the Customer object and the total amount to pay as two arguments.
The price list is stored in the text file “price_list.txt”. Each line in this file contains a 4-digit product code and unit price of an item. Write a readPriceList function to read the price list into the program. Store the data in a dictionary with product codes as keys and prices as values. Return the dictionary. The file “price_list.txt” has been created for you. You just need to download it from Blackboard.
The coupon list is stored in the text file “coupon_list.txt”. Each line in this file contains a 4-digit code and monetary value of a coupon. Write a readCouponList function to read the coupon list into the program. Store the data in a dictionary with the 4-digit codes as keys and monetary values as values. Return the dictionary. The file “coupon_list.txt” has been created for you. You just need to download it from Blackboard.
Write a scanPrices function for the customer to order items. First call the readPriceList function to read the price list from a text file. Display all items in the price dictionary. Then use a loop for the customer to enter product code of each item he wants. Every time a product code is entered, check to see whether the code is in the dictionary. If it is not, display “Item not found”. If the code is in the dictionary, display “Item found” and the price of the item. When the costumer has no more product code to enter, he types “9999” to exit the loop. The sacnPrices function will calculate, display and return the total price of all the items ordered.
Write a scanCoupons function for the customer to enter coupons. This function is very similar to the scanPrices function. It calls the readCouponList function to read the coupon list from a text file. Display all items in the coupon dictionary. Then use a loop for the customer to enter 4-digit code of each coupon he has. Every time a 4-digit code is entered, check to see whether the code is in the dictionary. If it is not, display “Coupon not found”. If the code is in the dictionary, display “Coupon found” and the value of the coupon. When the costumer has no more coupons to enter, he types “9999” to exit the loop. The sacnCoupons function will calculate, display and return the total value of all the coupons entered.
The makePayment function has two parameters to receive the Customer object and the total amount to pay. It asks the customer to choose a payment method. If the user chooses to pay by credit card, ask the user to enter the security code. Call the verifyCreditCard method of the Customer object to verify the security code. If the security code is incorrect, display “Security code incorrect. Payment rejected.” and loop back to ask the customer to choose payment method again. If the security code is correct, display on the screen the amount to be charged and the last four digits of the credit card number.
If the user chooses to pay by debit card, ask the user to enter the PIN. Call the verifyDebitCard method of the Customer object to verify the PIN. If the PIN is incorrect, display “PIN incorrect. Payment rejected.” and loop back to ask the customer to choose payment method again. If PIN is correct, display on the screen the amount to be charged and the last four digits of the debit card number.
The following shows a sample test run:
Welcome to Wake-Mart. Please register.
Enter your name: Clark Kent
Enter credit card number: 1234-5678-1234-5678
Enter 3-digit security code: 111
Enter debit card number: 9876-5432-9876-5432
Enter 4-digit PIN: 2222
Registration completed
Price list:
('4178', 8.0)
('6245', 4.88)
('5206', 4.25)
('2159', 0.99)
('6625', 2.99)
('1423', 7.88)
('1752', 4.99)
('6112', 5.77)
('2487', 12.52)
('2368', 5.25)
Enter 4-digit item code [or 9999 to stop]: 1243
Item not found
Enter 4-digit item code [or 9999 to stop]: 1423
Item found. Price: 7.88
Enter 4-digit item code [or 9999 to stop]: 2487
Item found. Price: 12.52
Enter 4-digit item code [or 9999 to stop]: 2368
Item found. Price: 5.25
Enter 4-digit item code [or 9999 to stop]: 9999
Total price: 25.65
Coupon list:
('7468', 1.99)
('8546', 1.29)
('7612', 1.49)
('7125', 0.99)
('8207', 0.59)
Enter 4-digit coupon code [or 9999 to stop]: 7162
Coupon not found
Enter 4-digit coupon code [or 9999 to stop]: 8207
Coupon found. Value: 0.59
Enter 4-digit coupon code [or 9999 to stop]: 7468
Coupon found. Value: 1.99
Enter 4-digit coupon code [or 9999 to stop]: 9999
Total coupon value: 2.58
Please pay this amount: 23.07
Please choose payment method.
Please enter 1 for credit card, 2 for debit card: 1
Please enter 3-digit security code: 222
Security code incorrect. Payment rejected.
Please choose payment method.
Please enter 1 for credit card, 2 for debit card: 2
Please enter 4-digit PIN: 1111
PIN incorrect. Payment rejected.
Please choose payment method.
Please enter 1 for credit card, 2 for debit card: 1
Please enter 3-digit security code: 111
The amount of 23.07 will be charged to card number ending with 5678
Zip your Python project and submit it to Blackboard for credit. Your Python project should have at least four files: a Python file containing the definition of Customer class, a Python file containing the main module, the text file “price_list.txt” , and the text file “coupon_list.txt”.
Explanation / Answer
main.py
====
from Customer import Customer
# Price list
price_list = {
'4178' : 8.0,
'6245' : 4.88,
'5206' : 4.25,
'2159' : 0.99,
'6625' : 2.99,
'1423' : 7.88,
'1752' : 4.99,
'6112' : 5.77,
'2487' : 12.52,
'2368' : 5.25
}
# Coupon list
coupon_list = {
'7468' : 1.99,
'8546' : 1.29,
'7612' : 1.49,
'7125' : 0.99,
'8207' : 0.59
}
def scanPrices():
for key, value in price_list.iteritems():
print "(" + key + " : " + str(value) + ")"
code = ""
selected = {}
while (code != "9999"):
code = str(raw_input(
"Enter 4-digit item code [or 9999 to stop]:" ))
try:
selected[code] = price_list[code]
print "Item found!, Price:", price_list[code]
except KeyError, e:
print "Item not found."
return selected
def scanCoupons():
for key, value in coupon_list.iteritems():
print "(" + key + " : " + str(value) + ")"
code = ""
selected = {}
while (code != "9999"):
code = str(raw_input(
"Enter 4-digit item code [or 9999 to stop]:" ))
try:
selected[code] = coupon_list[code]
print "Coupon found!, Price:", coupon_list[code]
except KeyError, e:
print "Coupon not found."
return selected
def makePayment(price, c1):
madePayment = False
while(not madePayment):
print "Please choose payment method."
res = raw_input(
"Please enter 1 for credit card, 2 for debit card:" )
if (res == '1'):
code = raw_input(
"Please enter 3-digit security code" )
if ( c1.verifyCreditCard(code) ):
madePayment = True
print "The amount of", price, "will be charged to card number ending with", c1.creditCardLastFour()
else:
print "PIN incorrect. Payment rejected."
elif (res == '2'):
code = raw_input(
"Please enter 4-digit security code" )
if ( c1.verifyDebitCard(code) ):
madePayment = True
print "The amount of", price, "will be charged to card number ending with", c1.debitCardLastFour()
else:
print "PIN incorrect. Payment rejected."
def main():
print "Welcome to Wake-Mart. Please register."
name = raw_input("Enter your name: ")
c1 = Customer(name)
credit = raw_input("Enter credit card number: ")
credit_sec = raw_input("Enter 3-digit security code: ")
debit = raw_input("Enter credit card number: ")
debit_sec = raw_input("Enter 3-digit security code: ")
c1.inputCardInfo(
credit, credit_sec,
debit, debit_sec )
print "Registration completed"
sel_items = scanPrices()
item_value = sum(sel_items.values())
print "Total Price: " + str(item_value)
sel_coupons = scanCoupons()
coupon_value = sum(sel_coupons.values())
print "Total Coupon value:", str(coupon_value)
print "Please pay this amount:", str(item_value - coupon_value)
makePayment(str(item_value - coupon_value), c1)
print "Buh bye :D"
main()
customer.py
====
class Customer(object):
"""Contains all Customer related members"""
def __init__(self, name):
self.name = name
self.cc_num = ""
self.cc_code = ""
self.dc_num = ""
self.dc_code = ""
def inputCardInfo(
self, cc_num, cc_code,
dc_num, dc_code):
self.cc_num = str(cc_num)
self.cc_code = str(cc_code)
self.dc_num = str(dc_num)
self.dc_code = str(dc_code)
def verifyCreditCard(self, cc_code):
"""Checks the Credit card cvv"""
return self.cc_code == cc_code
def verifyDebitCard(self, dc_code):
"""Checks the Debit card cvv"""
return self.dc_code == dc_code
def creditCardLastFour(self):
return self.cc_num[-4:]
def debitCardLastFour(self):
return self.dc_num[-4:]
Both files should be in the same directory.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.