-
Notifications
You must be signed in to change notification settings - Fork 10
Lottery ticket exercise
Suppose we want to design a system that allows users to create and participate in lotteries. The rules of the lottery are as follows:
- Someone creates a lottery with a secret "winning number" between 0 and 100.
- Anyone can purchase a lottery ticket for a set amount of money. A lottery ticket also has a random number between 0 and 100. If the lottery ticket's number is equal the lottery's number, that is a winning ticket.
- You can check whether a ticket is the winning ticket and redeem a winning lottery ticket for a set amount of money.
- You can only redeem a lottery ticket from the lottery where you bought the ticket. For instance, if you buy a lottery ticket from lottery1, you cannot redeem your ticket from lottery2, even if that ticket's number matches the winning number of lottery2.
Design, using pseudocode, a program to handle this lottery system. It is critical to the system that a lottery ticket can be redeemed only from the lottery where it was purchased. You can assume make the following assumptions:
- The creator and users have the lottery have accounts of some sort from which money can be withdrawn and deposited.
- We have a simple way of generating a random winning number for the lottery and lottery tickets.
Do not worry about writing code that resembles any particular language--we want to see the kind of code you would want to be able to write. The goal here is to see how people naturally go about solving a problem like this.
Suppose we also have a concept of ownership in our lottery system. If you buy a lottery ticket, the ticket belongs to you. You should only be able to redeem a winning lottery ticket if it belongs to you, but anyone can check whether a lottery ticket won. Answer the following questions:
- How can we handle this notion of ownership in this program?
- What should happen to a lottery ticket after it is redeemed?
- What would you call the relationship between a lottery and a lottery ticket?
Modify your code from part 1 to account for these changes.