关键词 > COSC2531

Programming Fundamentals (COSC2531) Assignment 2

发布时间:2024-05-16

Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

Programming Fundamentals (COSC2531) Assignment 2

Assessment Type

Individual assignment (no group work).

Submit online via Canvas/Assignments/Assignment 2.

Marks are awarded per rubric (please see the rubric on Canvas). Clarifications/updates maybe made via announcements.

Questions can  be  raised via the lectorial, practical   sessions  or Canvas discussion forum. Note the Canvas discussion forum is preferable.

Due Date

End of Week 12 (exact time is shown in Canvas/Assignments/Assignment 2) Deadline will not be advanced nor extended. Please check

Canvas/Assignments/Assignment 2 for the most up to date information regarding the assignment.

As this is a major assignment, a university standard late penalty of 10% per each day (e.g., 3 marks/day) applies for up to 5 days late, unless special

consideration has been granted.

Weighting

30 marks out of 100

1. Overview

The  main  objective  of  this  assignment  is  to  familiarize  you  with  object-oriented  design  and programming. Object-oriented programming helps to solve complex problems by coming up with a number of domain classes and associations. However, identifying meaningful classes and interactions requires a fair amount of design experience. Such experience cannot be gained by classroom-based teaching alone but must be gained through project experience. This assignment is designed to introduce different concepts such as inheritance, method overriding, and polymorphism.

You should develop this assignment in an iterative fashion (as opposed to completing it in one sitting). You can and should get started now (when this assignment specification is posted on Canvas) as there are concepts from previous lessons that you can employ to do this assignment. If there are questions, you    can    ask    via    the    lectorial,    practical     sessions    or    the    Canvas     discussion    forum (Canvas/Discussions/Discussion  on  Assessment  2).  Note  that  the Canvas discussion forum is preferable as it allows other students to seeyour questions as well. Also, you should ask questions in a general manner, for example, you should replicate your problem in a different context in isolation before posting, and you must not post your code on the Canvas discussion forum.

2. Assessment Criteria

This assignment will determine your ability to:

i.      Follow coding, convention and behavioural requirements provided in this document and in the course lessons;

ii.      Independently solve a problem by using programming concepts taught over the duration of the course;

iii.      Write and debug Python code independently;

iv.      Document code;

v.      Provide references where due;

vi.      Meet deadlines;

vii.      Seek clarification from your "supervisor" (instructor) when needed via the Canvas discussion forums; and

viii.      Create a program by recalling concepts taught in class, understand, and apply concepts relevant

to solution, analyse components of the problem, evaluate different approaches.

3. Learning Outcomes

This assignment is relevant to the following Learning Outcomes:

1.   Analyse simple computing problems.

2.   Devise  suitable  algorithmic  solutions and code these algorithmic solutions in a computer programming language.

3.   Develop maintainable and reusable solutions.

Specifically, upon the completion of this assignment, you will be able to:

•   Demonstrate knowledge of basic concepts, syntax, and control structures in programming

•   Devise solutions for simple computing problems under specific requirements

•   Encode the devised solutions into computer programs and test the programs on a computer

•   Demonstrate understanding  of standard  coding  conventions  and  ethical  considerations  in programming

4. Assessment Details

Please ensure that you have read Sections 1-3 of this document before going further.

Problem Overview: In this assignment, you are developing a pharmacy management system as in Assignment 1 using the Object-Oriented Programming (OOP) paradigm. Same as in Assignment 1, the pharmacists are the ones that use this system to process and print out receipts of the customers’ purchases. You are required to implement the program following the below requirements. Note the requirements in this assignment are sometimes slightly different and more complex compared to those in Assignment 1. Also, we will provide you with some sample .txt files (download on Canvas), but you should change the data in these files to test your program as during the marking, we will use different text files to test your program.

Requirements: Your  code  must  meet  the  following functionalities, code,  and documentation requirements. Your submission will be graded based on the rubric published on Canvas. Please ensure you read all the requirements and the rubric carefully before working on your assignment.

A - Functionalities Requirements:

There are 4 levels, please ensure you only attempt one level after completing the previous level.

------------------------------------------- PASS Level (10 marks) ------------------------------------------

At this level, your program will have some basic classes with specifications as below. You may need to define methods wherever appropriate to support these classes. At the end of the PASS level, your program should be able to run with a menu described in the class Operations.

Customers:

1.   Class Customer

Each customer has a unique ID, unique name (a name will only contain alphabet characters). Each customer also has  some reward points. You are required to write the class named Customer to support the following:

i.      Attributes ID, name, and reward

ii.      Constructor takes the values of ID, name, and reward as arguments

iii.      Appropriate getter methods for the attributes of this class

iv.      A method get_reward which should be an empty super method

v.      A method get_discount which should be an empty super method

vi.      A method update_reward which should be an empty super method

vii.      A method display_info which should be an empty super method

2.   Class BasicCustomer

All Basic customers have a flat reward rate when making a purchase (i.e., all Basic customers have the same reward rate). By default, the flat reward rate is 100%. The class BasicCustomer should have the following components:

i.      An attribute for the reward rate

ii.      Constructor takes the appropriate parameters/arguments.

iii.      Appropriate getter methods for the attributes of this class

iv.      A method get_reward which takes the total cost and returns the reward. Note, the reward is always rounded. For example, when the total cost is 14.8 and the reward rate is 100%, then the method will returns the reward which is round(14.8 x 100%) = 15.

v.      A method update_reward which takes a value and increase the attribute reward with that value.

vi.     A method display_info that prints the values of the BasicCustomer attributes.

vii.      A method set_reward_rate to adjust the reward rate. This method affects all Basic customers.

3.   Class VIPCustomer

A VIP customer not just receives the reward but also gets a discount for the purchase. The reward rate is the same for all VIP customers and has the default value of 100%. On the other hand, the discount rate is different among VIP customers. If not specified, the discount rate is set as 8%.

Note that the reward is computed after the discount. For example, with a reward rate of 100% and discount rate of 8%, if a VIP customer makes a purchase with the original total cost of 30$, then discount will be 30 x 8% = 2.4$, the total cost after the discount is 27.6$, and thus, the reward is round(27.6 x 100%) = 28.

The class VIPCustomer should have the following components:

i.  Appropriate attributes to support the reward rate and discount rate

ii.  Constructor takes the appropriate parameters/arguments

iii.  Appropriate getter methods for the attributes of this class

iv.  A method get_discount which takes the total cost and returns the discount offered v.  A method get_reward which takes the total cost and returns the reward

vi.  A method update_reward which takes a value and increase the attribute reward with that value.

vii.  A method display_info that prints the values of the VIPCustomer attributes

viii.  A method set_reward_rate to adjust the reward rate. This method affects all VIP customers

ix.  A  method set_discount_rate to  adjust  the  discount  rate  of  each  individual  VIP customer

Products:

4.   Class Product

This class is to keep track of information on different products that the pharmacy offers. This class supports the following information:

ID: a unique identifier of the product

name: the name of the product (you can assume the product names are unique and they do not include any digit)

price: the unit price of the product

•   A method display_info that prints the values of the Product attributes

•   Extra attributes and methods if you want to define

Orders

5.   Class Order

This class is to store a customer's purchase information. This class supports the following information of an order:

customer: the one who makes the purchase (can be a Basic or VIP customer). You need to think/analyse carefully if this should be an ID, name, or something else.

product: the product of the purchase. You need to think/analyse carefully if this should be an ID,name, or something else.

quantity: the quantity of the product ordered by the customer

•   A  method compute_cost that  returns  the  original  total  cost  (the  cost  before  the discount), the discount, the final total cost (the cost after the discount), and the reward. For example, if the original total cost of an order of the customer Tom (VIP customer with reward rate of 100% and discount rate of 8%) is 30, then this method will return (30, 2.4, 27.6, 28).

•   Extra attributes and methods if you want to define.

Records

6.   Class Records

This class is the central data repository of your program. It supports the following information:

a list of existing customers - you need to think what you should store in this list (customer ID, customer name, or something else?)

a list of existing products - you need to think about what you should store in this list (product ID, product name, or something else?)

•   This class has a method named read_customers. This method takes in a filename and then read and add the customers in this file to the customer list of the class. In the sequel, we call this the customer file. See an example of the customer file below.

In this file, the customers are always in this format: customer_ID, customer_name, reward rate, discount_rate (if that is a VIP customer), and reward. For example, in the 1st  line, the customer_ID is B1, the name is James, the reward rate is 100%, and the reward point is 20. In the 3rd line, the customer_ID is V3, the name is Tom, the reward rate is 100%, the discount rate is 8%, and the reward point is 12. A Basic customer has an ID starting with the letter "B" whilst a VIP customer has an ID starting with the letter " V". The numbers in the ID after these characters (B, V) are all unique (i.e., 1, 2, 3, 5 … are unique; for example, if there is a customer with the ID of B1, there won't be a customer with the ID of V1). In this part, you can assume there will be no error in this customer file (e.g., the data format is always correct, and the reward and discount values are always valid).

•   This class has another method named read_products. This method takes in a filename and can read and add the products stored in that file to the product list of the class. In the sequel, we call this the product file. See an example of the product file below.

In  this  file,  the  products  are  always  in  this  format: product_ID, product_name, unit_price. The product ID always starts with the letter "P ". The product IDs and names are all unique. You can assume there will be no error in this file (e.g., the data format is always correct, and the values are always valid).

•   This class also has two methods find_customer and find_product. These methods take in a search value (can be either a name or an ID of a customer or product), search through   the    list   of   customers/products    and    then   return    the   corresponding customer/product if found or return None if not found.

•   This class also has two methods list_customers and list_products. These methods can display the information of existing customers and products on screen. The method list_customers will display the customer ID, name, the reward rate, the discount rate

(for VIP customers), and the reward. The method list_products will display the product ID, product name, and the unit price. Note the two methods can be used to validate the reading from the two .txt files associated with the customers and products.

NOTE you are allowed to add extra attributes and methods in this class if these attributes and methods make your program more efficient.

Operations

7.   Class Operations

This can be considered the main class of your program. It supports a menu with the following options:

i. Make  a purchase:  this  option  allows  users  to  make  a  purchase  for  a  customer.  Detailed requirements for this option are below (Requirements v-ix).

ii. Display existing customers: this option can display all the information of all existing customers: ID, name, reward rate, discount rate (only for VIP customers), and reward.

iii. Display existing products: this option can display all the information of all existing products: ID, name, and unit price.

iv. Exit the program: this option allows users to exit the program.

Other requirements of the menu program are as follows:

v.      When the program starts, it looks for the files customers.txt (the customer file) and products.txt (the product file) in the local directory (the directory that stores the .py file of the program). If found, the data will be read into the program accordingly, the program will then display a menu with the 4 options described above. If any file is missing, the program will quit gracefully with an error message indicating the corresponding file is missing.

vi.      Your menu program will  allow the user to make  a purchase as  specified in PART  1  of Assignment 1. In this part, like in PART 1 of Assignment 1, you can assume users always enter valid customer names, products, and quantities. Note that for VIP customers, the final total cost = the original cost - discount, and the earned reward points are computed by the final total cost.

vii.      When a customer finishes making a purchase,

a.   If the customer is a new customer, the program will add the information of that customer into the data collection (think/analyse carefully which information needs to be added). Any new customer will be registered as a Basic customer.

b.   If the customer is an existing customer, the program will print out a message showing the customer type (e.g., Basic/VIP customer), then proceed with the purchase and display the receipt.

viii.      The receipt of a purchase of a Basic customer can be displayed as a formatted message as below.

Receipt

Name:

Product:

Unit Price:

Quantity:

    (AUD)

Total cost:                 ost> (AUD)

Earned reward:


The receipt of a purchase of a VIP customer can be displayed as a formatted message as below.

Receipt

Name:

Product:

Unit Price:

Quantity:

    (AUD)

Original cost: (AUD)

Discount:                    (AUD)

Total cost:                 ost> (AUD)

Earned reward:

ix.      When a task is accomplished, the menu will appear again for the next task. The program always exits gracefully from the menu.


---------- CREDIT level (4 marks, please do not attempt this level before completing the PASS level) ------------


Operations

i.     At this level, your program will need to have the feature i) specified in PART 2 of Assignment 1 (i.e., each product will belong to one of the two categories: can be purchased without a doctor’s prescription or can only be purchased with a doctor’s prescription). In this level, the format of the product file products.txt will look as follows:

Each line in the product file has the following format: product_ID, product_name, unit_price, dr_prescription. The value of dr_prescription could be n (meaning no) or y (meaning yes). You will need to think of which parts of your program  and which classes to be updated for your program to satisfy this feature.

ii.    Besides, at this level, your program needs to handle exceptions compared to the PASS level. At

this level, you are required to define various custom exceptions to handle the below issues:

a.   Display an error message if the customer’s name entered by the user contains non-alphabet characters. When this error occurs, the user will be given another chance, until a valid name (names contain only alphabet characters) is entered.


b.   Display an error message if the product entered by the user is not a valid product. When this error occurs, the user will be given another chance, until a valid product is entered.

c.   Display an error message if the quantity entered is 0, negative, or not an integer. When this error occurs, the user will be given another chance, until a valid quantity is entered.

d.   Display an error message if the answer by the user is not y orn when asking if the customer has a doctor’s prescription. When this error occurs, the user will be given another chance, until a valid answer (i.e., y, n) is entered.

iii.   Furthermore, in this level, in the "Make a purchase" option, your program will allow ordering a Bundle, which is a special product. It means multiple products can be offered together as one product. For example, a bundle can consist of vitaminC, vitaminE, and vitaminD. You can assume all parts of a bundle are existing products in the system. If in the bundle, there exists a product that requires a doctor’s prescription, then the bundle will require a doctor’sprescription.

The price of a bundle is 80% of the total price of all individual products. For example, if vitaminC costs 12.0$, vitaminE costs 14.5$, and vitaminD costs 15.2$ then the price of this bundle is 80% x (12.0 + 14.5 + 15.2) = 33.36$.

To support this feature, you need to add one more class to your program.

8.  Class Bundle: Each bundle has a unique ID and name (as with Product). You need to define the appropriate variables and methods to support the class Bundle.

With this modification, the product file products.txt at this level now may look like this:

The ID of a Bundle always starts with the letter "B". Note that the data format of a bundle is different compared to a normal product; it includes the IDs of the product components. The IDs/names of the products and bundles are all unique. You can assume all the products in a bundle are existing products and unique (no duplicates). You can assume bundles are always stored at the end of a file, after all normal products.

iv.     At this level, for the option "Display existing products", when displaying bundles, your program will display the bundle’s ID, name, the IDs of the components, the unit price, and the doctor’s prescription requirement. On the other hand, the products information is the same as in the PASS level + the doctor’s prescription requirement.

v. Finally, your program should support both IDs and names of the customers, products/bundles for any functions that use this information. For example, instead of entering the customer names, product/bundle  names,  now,  the  user  can  enter  the  customer  IDs  and  product/bundle  IDs, respectively.

---------- DI Level (4 marks, please do not attempt this level before completing the CREDIT level) -----------

In this level, there are some additional main features for some classes in your program. Some features might be challenging. Details of these features are described as follows.

Operations

Your program now has the following new features.

ii.      In this level, in the "Make a purchase" option, your program will allow customers to enter multiple products and quantities in one order. The requirements areas in Assignment 1 for this option (requirement 1 of PART 3). You can modify the existing classes or design extra classes to support this requirement. Note that in this level, in the option "Make a purchase", your program  can  deduct  the  reward  points  of  a  customer  before  finishing  a  purchase.  The specification is as in Requirement 2 of PART 3 in Assignment 1. Note that the deduction of the reward points is from the final total cost.

i.      Your program now has an option "Add/update information of products" to add products. The specification  is  same  as  Assignment   1  for  this  option  (requirement  2  in  PART  2  and requirement 3 in PART 3).

ii.      Your program now has an option "Adjust the reward rate of all Basic customers " to adjust the reward rate of all Basic customers. This adjustment will affect all Basic customers in all future orders. Invalid inputs (non-number or 0 or negative rate) should be handled via exceptions; the user will be given another chance until a valid input is entered. Note that in this option, if the user enters 1, this means the reward rate is 100%.

iii.      Your program now has an option "Adjust the discount rate of a VIP customer". The option will ask for the name or ID of a VIP customer, then ask for a new discount rate. Invalid customers (non-existent or non-VIP customers) needs to be handled, i.e., your program will give the user another chance until a valid VIP customer is entered. Invalid inputs (non-number or 0 or negative values) should also be handled via exceptions, and the user will be given another chance until a valid input is entered. Note that your program should support both customers' IDs and names in this option, i.e., users can type either the customer's name or the ID. Besides, note that in this option, if the user enters 0.2, this means the discount rate is 20%.

iv.     Note, in this part, you need to analyse the requirements and update some classes so that your program can satisfy the requirements listed above.