Question: Programming Project Objectives In this programming project, students will learn: - How to design and define a class - How to create and use objects
Programming Project
Objectives
In this programming project, students will learn:
- How to design and define a class
- How to create and use objects
- How to write code to read data from text files
- How to create and use dictionaries
Goals
In this lab assignment, students will demonstrate the abilities to:
- Design and define a class
- Create and use objects
- Write code to read data from text files
- Create and use dictionaries
Instruction
This programming project has just one program and thus, uses just one PyCharm project, called WakeMart. Please follow exactly the program specifications given, including the names given for the instance variables, class methods, and the function names in the main module. Following program specifications is a large part of learning how to program. 10 points will be automatically deducted for any extra functionality added to this program, even if it produces the same output. This project is worth 10% of your final grade. You will be given a week to complete the assignment. You are to work on this on your own - no group work. If you do not have access to PyCharm at home, then arrange a time to meet with me to use a classroom with PyCharm. The coding for this can be completed in Notepad or Notepad++. You can then come to classroom to test it in PyCharm. See the rubric at the end of this file.
Your local variable names must follow either the camel case or underscore convention, and be of reasonable lengths and still be meaningful:
Camel case (Java - like):
All variables contain either lowercase letters or numeric digits, except when there are multiple words in the variable name. Each word after the first must start with an uppercase letter.
Examples:
number
numStudents
isValid
Underscore (C++ - like):
All variables contain either lowercase letters or numeric digits, except when there are multiple words in the variable name. Each word after the first must be separated by an underscore character.
Examples:
number
num_students
is_valid
Please use PyCharm to type and test your programs.
Create a Python project for the following program, called WakeMart, with the two program code files, customer.py and wakeMart_main.py, and two input files, price_list.txt and coupon_list.txt. Once the program is thoroughly tested, zip the Python project into a zip file called WakeMart.zip. Submit the zip file to Blackboard for credit.
Your project will not be graded if it does not follow the above project submission directions, exactly.
In Lab 12 you wrote a program for WakeMart customers to check out grocery items. Now, WakeMart wants an upgrade of the system.
First, they want the customer to register with the store before ordering items. They only accept payment by credit card or debit card now. The customer must enter card information during the registration process. The customer must enter their 16-digit card information during the registration process (separated by dashes, every four digits).
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. These 4-digit codes are read in from a file and treated as strings, not integers.
The following lists the specifications of this project:
You are given two input data files to be placed in the project directory of PyCharm. They will contain the price codes and prices and the coupon codes and values, as explained further below.
Define a Customer class in the customer.py file. 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 7 class methods. The following UML class diagram shows the design of this class:
| Customer |
| -name: String -credit_card_num: String -credit_sec_code: String -debit_card_num: String -debit_pin: String |
| +create (name: String) +inputCardsInfo() +verifyCreditCard (security_code: String): Bool +verifyDebitCard (pin: String): Bool +getCreditCardLastFour(): String +getDebitCardLastFour(): String +__str__: String |
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 each one to an empty string.
In the inputCardInfo method, the user enters his credit card number, credit card security code, debit card number and debit card PIN. Each of these input values should be stored in the appropriate instance variables. The credit and debit cards have 16-digits separated by dashes, the credit card security code is 3-digits stored as a string and the debit PIN code is 4-digits stored as a string. Please do NOT use any input validation, assume the user entered the information correctly.
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 getCreditCardLastFour method returns the credit card number as 12 asterisks followed by the last four digits of the credit card number with separating dashes.
The getDebitCardLastFour method returns the debit card number as 12 asterisks followed by the last four digits of the debit card number with separating dashes.
The __str__ method returns a string containing the customers name, his credit card number as 12 asterisks followed by the last four digits and his debit card number as 12 asterisks followed by the last four digits. The card information should be displayed with dashes separating every four digits. For example, if the card number is 1234-5678-8765-4321, then return it as ****-****-****-4321.
The wakeMart_main.py module of the project must have the following six functions.
main: The main function contains the mainline logic. It starts by asking the customer to enter his name. Use it to create a Customer object. Next, call the inputCardsInfo method of the Customer object to input credit card and debit card information. Display this information using the print function and only the object name. Next, call the scanPrices function for the customer to order items. This function returns the total price of the items. Use the return value to calculate how much the customer needs to pay. Display this amount on the screen. Next, call the scanCoupons function for the customer to enter coupons. This function returns the total value of the coupons. Use the return values to calculate how much the customer needs to pay. Display this amount on the screen. Lastly, call the makePayment method to process payment. Pass the Customer object and the total amount to pay as two arguments.
readPriceList: The price_list.txt text file in the WakeMart project directory contains the items in the price list. Each line in this file contains a 4-digit product code and unit price of an item. The product code must be treated as a string, not an integer. The price must be converted from string to float. Write this readPriceList function to read the price list into the program. Store the data in a dictionary with the 4-digit product codes as keys and the prices as values. Please review Lesson 11, slides 61-62 and Lesson 12, slides 18-19. Return the dictionary.
readCouponList: The coupon_list.txt text file in the WakeMart project directory contains the coupons in the coupon list. Each line in this file contains a 4-digit coupon code and the monetary value of the coupon. The coupon code must be treated as a string, not an integer. The value must be converted from string to float. Write this readCouponList function to read the coupon list into the program. Store the data in a dictionary with the 4-digit coupon codes as keys and monetary values as values. Please review Lesson 11, slides 61-62 and Lesson 12, slides 18-19. Return the dictionary.
scanPrices: 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 as tuples, one per line. (Note: There is a special dictionary method for this.) Then use a loop for the customer to enter the 4-digit product code of each item he wants to buy, read in as a string. Every time a 4-digit 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 customer has no more items to enter, he types 9999 to exit the loop. This scanPrices function will calculate, display and return the total price of all the items ordered.
scanCoupons: Write a scanCoupons function for the customer to enter coupons. First, call the readCouponList function to read the coupon list from a text file. Display all items in the coupon dictionary as tuples, one per line. (Note: There is a special dictionary method for this.) Then use a loop for the customer to enter the 4-digit code of each coupon he has, read in as a string. Every time a 4-digit coupon 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 customer has no more coupons to enter, he types 9999 to exit the loop. This scanCoupons function will calculate, display and return the total value of all the items ordered.
makePayment: The makePayment function has two parameters one to receive the Customer object and the other one to receive the total amount to pay. First, ask the customer to choose a payment method.
If the user chooses to pay by credit card, ask the user to enter the security code and 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 the payment method again. This is where you are to use an input validation loop. 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 and 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 the payment method again. This is where you are to use an input validation loop. If PIN is correct, display on the screen the amount to be charged and the last four digits of the debit card number.
If you add in meaningful method and function comments, using docstring, I will give you up to 10 pts extra credit.
The following shows a sample test run: Your program will not be tested with this exact input:
Welcome to WakeMart. Please register.
Enter your name: Bruce Banner
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
You entered:
Name: Bruce Banner
Credit Card: ****-****-****-5678
Debit Card: ****-****-****-5432
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 ****-****-****- 5678
Zip your Python project as WakeMart.zip and submit it to Blackboard for credit. Your Python project should have four files:
customer.py
wakeMart_main.py
price_list.txt
coupon_list.txt
Grading
Writing __init__ method of Customer class [6 points]
Writing inputCardInfo method of Customer class [5 points]
Writing verifyCreditCard method of Customer class [5 points]
Writing verifyDebitCard method of Customer class [5 points]
Writing getCreditCardLastFour method of Customer class [6 points]
Writing getDebitCardLastFour method of Customer class [6 points]
Writing __str__ method of Customer class [6 points]
Writing main function [9 points]
Writing readPriceList function [11 points]
Writing readCouponList function [11 points]
Writing scanPrices function [10 points]
Writing scanCoupons function [10 points]
Writing makePayment function [10 points]
Please read the instruction carefully honestly. Thank you.
Oh and please if you can which it would help me alot, can you seperate which py. needs what in it? Thanks in advance
The list that they are asking for has these numbers:
Coupon list:
7468,1.99 8546,1.29 7612,1.49 7125,0.99 8207,0.59
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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
