Homework 8 Homework 8 Event Driven Programming Due Sunday, November 12th, 2013 at 11:59 PM In this homework, you will implement the lemonade stand game that was briefly described in the bonus question for homework 7. You are asked to run a lemonade stand for one week. You borrow $10.00 from your father and find a stand in a crowded area of a market. You use the $10 to buy ingredients for lemonade. Each day, you check the weather forecast in terms of temperature and humidity to set the price for each cup of lemonade. The weather forecast may or may not be accurate. Once the price is set and your start selling on a particular day, you are not allowed to change the price of lemonade during that day. You need the following ingredients to make lemonade: • • • Lemons Sugar Ice You can use the initial $10.00 to buy different amount of each item. The game runs in 7 rounds, with each round constituting your sales for one day. You buy enough ingredients for one day, set the price for each cup of lemonade for that day and run the simulation for one day. The number of customers for your lemonade depends on the price of a cup, and the weather conditions. The ingredients for lemonade should be priced at the following rates: sugar = $1 per kg with 100 grams in each cup of lemonade ice = $2.50 per bag with 0.05 bags used in each cup lemons = $0.5 for each lemon and 1 lemons make 3 cups. Task 1: [20 points] The User Interface: Create a user interface for the game that should be graphical using Tkinter. Your interface should following the example given below but can be more creative. You will be graded on your creativity – so let your imagination run wild!! 1 Homework 8 Day: 1 There are four images at the bottom that act as buttons. If the user clicks on the image, your program should allow the user to buy 1 Kg of sugar. The user should be given a confirmation dialog before purchasing the sugar as given below: 2 Homework 8 The button should allow the users to buy 1 lemon and the button should allow the users to buy 1 bag of ice. Each purchase should be preceded by a confirmation dialog. The user interface should display the current quantities of sugar, ice, lemons, money, and weather forecast at all times. The weather forecast should be a random temperature between 60 degrees and110 degrees while the humidity should be a random number between 0 and 100. The user should be able to set the price of each cup of lemonade by using the Entry Widget and “Set Price” button at the bottom. The updated price should be shown on the user interface. When everything is setup, the user should be able to start one day of selling by clicking the interface should indicate which day will be run next. button. The user Task 2: [10 points] Simulation: In this task, you will provide the functionality to run sales for one day. This task will be initiated by the user by clicking the “Start Selling” button. Once the user clicks this button, your program should do the following steps: 1. Lock any input from the user during the simulation. The user cannot buy anything or change price while the simulation is running. 2. Generate actual weather for the day. The temperature should have an error in the range (20,+10) from the forecast temperature. For example if the forecast temperature was 75 degrees, then actual temperature should be something between the range (75-20, 75+10). The actual humidity should be ±25 of predicted humidity without going below 0 or above 100. 3. Update the user interface with actual temperature. 3 Homework 8 4. Calculate show many customers will visit the lemonade stand. The number of customers depends on the current weather conditions and the price per cup. You can use the following relationships or invent your own that work better. a. Depending on the temperature, you will have anywhere between 0 and 40 customers. If the temperature falls below 60 degrees, you will have 0 customers and if any temperature above 110 will have 40 customers. In between 60 and 110 will be a linear function with number of customers increasing from 0 to 40 as temperature goes from 60 to 110. b. Humidity will add more customers to the count independent of temperature. A humidity of below 30% will not add customers. Humidity of 30% will add three more customers, humidity of 40% will add 4 customers, and a 100% humidity will add 10 more customers. c. The price of lemonade adversely affects the number of customers. A price of more than $2.00 will scare all customers and nobody will buy any lemonade. High prices will subtract from number of customers with $2.00 subtracting 100% of customers and $0.10 subtracting 0% customers. 5. Process the customers. This could be as simple as subtracting appropriate amounts from the ingredients for each cup sold and adding sale price to total money. Keep in mind that if you run out of an ingredient, you cannot process any more customers. A more fancy way of this would be to animate customers coming in until either all customers are served or you run out of an ingredient. 6. End simulation of one day and update the interface with forecast for next day. 7. The simulation should be disabled after 7 days. You should also provide a restart button on the interface that will reset the application and allow the user to play again. Task 3: [10 points] Style: You will be graded on the quality of your comments, choice of variable names, and your decisions to modularize your code into functions that are logical. 4