Question
A factory makes products using parts that are identified by letters A to L. Each product is made of at least 3 different parts, and
A factory makes products using parts that are identified by letters A to L. Each product is made of at least 3 different parts, and is identified by a product code made up of letters identifying the parts. The letters in a product code is sorted alphabetically. E.g., a product with product code ABBBG is made up of 1 A, 3 B and 1 G parts. (a) Write and develop a function getPartsInCode which has one string parameter: productCode. The function returns a string in this format: n1p1 n2p2 nkpk. Note nipis are separated by space. For example, if product code is ABBBG, then the function returns 1A 3B 1G. Note that the letters in the string parameter are in uppercase and are already sorted. You can use collections of only str type for function. This means collection types such as set, list, dict are not allowed. Apply and employ structured programming and write an application to manage the factory. Other than the data specified in Q2(b), you may use collections of any types for other data in your application. However, you should assume that the user input for product code is not sorted alphabetically. (b) Initialise the following program data in your main method (that is, these variables are not global variables): The stock level for each part is 100 at the start of the application. startLevel = 100 The reorder point for each part is 20. Once the stock level is 20 or below, the part should be reordered. reorderPoint = 20 A string records the letters A L. One letter is used to identify a part in the factory. partIds = 'ABCDEFGHIJKL' An un-nested list records the stock level of each part. The stock level for each part starts with the value recorded in startLevel. For example, stock level for part A should be recorded at the 0-index, stock level for part B should be recorded at the 1-index, etc. Use another un-nested list to store existing product codes. Start the list empty. (c) Offer this menu repeatedly until option 0 is selected to end the application: Menu 1. Add product code 2. List inventory 3. Update inventory 4. Make product 5. Get summarised data 0. Exit Respond to the menu choices according to the description below. (3 marks) Add product code The program reads a product code. Note that as the letters may be unsorted when it is entered and the letters may be in uppercase or lowercase. The program first sorts the product code and then checks whether the code is valid. A valid code fulfills these criteria: o The code is at least 3 characters in length. o Each character is a letter from A to L. If the code is valid, the program adds it to a list of product codes if the code is not already in the list of product codes. Display the following messages where appropriate: o The product code is invalid o The product code already exists o The product code has been added successfully Example runs: Run 1 Enter new product code: abcz The product code is invalid Run 2 Enter new product code: abdc The product code has been added successfully Note that the code added is ABCD (sorted and in uppercase) Run 3 Enter new product code: acbd The product code already exists List inventory The stock level for each part is listed. Note that parts that should be reordered are displayed with asterisk. Example run: Part Stock Level A 100 B 100 C 100 D 100 E 12 *** F 100 G 100 H 20 *** i 100 J 100 K 100 L 100 Legend: *** stock level at or lower than reorder point 20 Update inventory This option allows the stock level of one or more parts to be restocked. The program repeatedly reads part identifier and the amount to add to the stock level for the part, until an empty string is entered for the part identifier. Each update of a part should be recorded in a file, transactions.txt on separate line in this format: restock letter quantityAdded Example run: Enter part identifier or to end: T The part identifier is invalid Enter part identifier or to end: E Current stock level for E = 12 Enter quantity to add: 0 The quantity is invalid Enter part identifier or to end: E Current stock level for E = 12 Enter quantity to add: -2 The quantity is invalid Enter part identifier or to end: E Current stock level for E = 12 Enter quantity to add: 60 Updated stock level for E = 72 Enter part identifier or to end: F Current stock level for F = 100 Enter quantity to add: 10 Updated stock level for F = 110 Enter part identifier or to end: Content of transaction.txt restock E 60 restock F 10 Make product This option allows a product code and a quantity to make to be entered. Again, assume that the letters in product code is unsorted and may be in uppercase or lowercase. You must use the function getPartsInCode in Q2(a). Display the following messages where appropriate: o Invalid product code y where y is an non-existing product code. o Invalid quantity x where x is the a quantity to make, if x is zero or negative. o x product y successfully made where x is the quantity made and y is the product code. The inventory should be updated. o x product y made at the current inventory level. z outstanding. where x is the quantity made, z is the quantity that cannot be fulfilled, and y is the product code. The inventory should be updated according to the quantity made. If a part is made and/or if there is outstanding product quantity, the details should be recorded in a file, transactions.txt on separate line in this format: o if the product is made, record in this format: make code quantityMade o if there is outstanding product quantity, record in this format: outstanding code quantityOutstanding Example runs: Run 1 Enter product code: ABCD Invalid product code ABCD Run 2 Enter product code: ABBB Enter quantity to make: -2 Invalid quantity -2 Run 3 Enter product code: ABBB Enter quantity to make: 2 2 product ABBB successfully made Run 4 Enter product code: ABBB Enter quantity to make: 2 Insufficient inventory. 1 product ABBB made at the current inventory level. 1 outstanding. Content of transaction.txt # add to previous contents make ABBB 2 make ABBB 1 outstanding ABBB 1 Get summarised data Prompt and read the type of data (0-restock, 1-make, 2-outstanding) the summary is for. Then, open a file transactions.txt with an appropriate file mode, to produce the summarized report, sorted by quantity followed by either by part or product code. Example runs: Assume the following 12 lines are in transactions.txt: make ABBB 2 make ABBC 2 make ABBB 1 outstanding ABBB 1 restock E 60 restock F 10 restock A 60 make ABBC 12 make ABBB 2 make ABBB 2 outstanding ABBB 2 restock F 10 Run 1 0-restock, 1-make, 2-outstanding. Enter choice: 0 Summarised Data for RESTOCK *** A 60 E 60 F 20 Run 2 0-restock, 1-make, 2-outstanding. Enter choice: 1 Summarised Data for MAKE *** ABBC 14 ABBB 7 Run 3 0-restock, 1-make, 2-outstanding. Enter choice: 2 Summarised Data for OUTSTANDING *** ABBB 3
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started