In short: In this project, you are asked to create a program to simulate a General Goods Store. Your store should includ
Posted: Fri Jul 08, 2022 6:39 am
In short: In this project, you are asked to create a program to simulate a General Goods Store. Your store should include three arrays of size 5: the first should include the names of your goods (you can set these yourself), the second the price of each good (you may also set these), and finally the third should contain the current stock of each good (randomly determined). All three arrays should correspond to each other based on index (i.e. index 0 in names corresponds to index 0 in prices and index 0 in stock). Allow a user to purchase goods as long as an item is in stock and the user still has money. In more detail: Create a Store class with four attributes, a decimal for the shop earnings, a string array of prod- uct names, a decimal array of product prices, and an int array of product stock. The first two arrays may be completely set by the programmer, but the third should be randomly decided at instantiation. Your constructor should call the method Stock to randomly set the stock of each item to a value between 0 and 10, both inclusive. • The Stock method should iterate through the array, setting a random value between 0 and 10 for each item. It need not take any arguments nor return any value. • Include a purchase method with two arguments, a string itemName and decimal funds. If itemName matches an item in your name array, increase your earnings based on the item price and decrease the stock by one. If there is no match for itemName, the user does not have enough funds, or if it is out of stock, have the method return -1, else return the user's adjusted funds. . Include a ToString method to display all items with their corresponding prices and stock. In the Main method 27 June 2022 Project #2 CSCI 1301 Page 1 of 5 • Instantiate a Store object. • Ask the user for his or her starting funds. If the value is not a number or is less than 0, keep asking until you get a sensible value. • Display the current state of your shop with ToString. . Ask the user what he or she wishes to purchase. Call the Purchase method. If Purchase returns -1, tell the user that the selection was invalid, else set the user's budget to the returned value. • Ask the user if that will be all after each item, quitting if the user says "Yes" or "Y" with any capitalization.
Example: Here is a sample execution: Welcome to my General Goods Store. What is your current budget? Pocket Lint This is nonsensical, what is your current budget? -54 This is nonsensical, what is your current budget? 200 Great! Your budget is $200.00. Our current stock is: Water $1.00 8 Candy $0.25 3 Pencil $0.10 0 Book $9.99 1 32" LED Television $299.97 6 What would you like to purchase? Nothing I'm sorry, but that was an invalid selection. Would you like to make another purchase? Enter "Yes" or "Y" to continue. yes What would you like to purchase? Pencil I'm sorry, but that was an invalid selection. Would you like to make another purchase? Enter "Yes" or "Y" to continue. What would you like to purchase? Water Thanks for the purchase! Your budget is now $199.00. Our current stock is: Water $1.00 7 Candy $0.25 3 Pencil $0.10 0 Book $9.99 1 32" LED Television $299.97 6 Would you like to make another purchase? Enter "Yes" or "Y" to continue. not Thanks for your business! Please come again!