home—lectures—recipe—exams—hws—D2L—breeze (snow day; distance)
union-types
working with a union type
hw03b
Due: Sep.25 (Mon) 15:00 (hardcopy and D2L)
(but try to have it mostly-completed by Friday evening)
Your submitted file should be named “hw03.rkt”.
Note: There are also some D2L questions under a quiz named “hw03a”.
We wish to write code about whether or not the Radford Highlanders
won their soccer game, this last weekend.
We want to capture whether: they won/lost, or tied, or there wasn't any game
this weekend, or (if the game is still in-progress) what the name of the team
currently being played is.
- (5pts) Complete steps 1-3 of the-design-recipe—the design recipe: final version for representing this information,
which we'll name “game-result”.
Hint:
To represent whether they won or lost, a boolean seems appropriate.
What types seem appropriate for each of the other variants?
- (5pts) Write a function payout which takes in the amount of a bet
placed that the Highlanders’ would win their game (non-negative)
and a game-result
and returns how much money is to be repaid:
- If the Highlanders win, twice the money is repaid, minus a 10% house cut.
- If the Highlanders lose, $0 is repaid.
- If the Highlanders are still playing, nothing ($0) is repaid (yet).
- If the Highlanders tie, the amount of the bet is repaid, minus a 10% house cut.
- If the Highlanders didn't play, then the amount of the bet is fully refunded.
- (5pts) Write a function game-result->string which returns
a user-friendly message similar to one of the following, as appropriate:
- "The Radford Highlanders won!" (or, “lost :-(”)
- "The Radford Highlanders tied their last game."
- "The Radford Highlanders are still playing The Wytheville Wallabies."
Hint:
Of course, it is not “as appropriate”
to return a string mentioning the
Wytheville Wallabies
when we're actually playing the
Dublin Dingoes,
or the
Pulaski Pangolins!
Recall from our data-definition in #1, a game-result should capable of representing,
among other things, the name of a team (which therefore means that the game must be in-progress).
(Moreover, this means your function does not need to be given any additional information,
since the game-result already represents the info you need.)
- "The Radford Highlanders did not play this week."
(You will, of course, follow the applicable steps 4,5,7,8 of the-design-recipe—the design recipe: final version.)
Standard instructions for all homeworks (unless instructed otherwise):
-
Your name,
the assignment-number,
and
the URL of this assignment
must be in a comment at the start of the file.
-
Test cases may be worth half the points or perhaps even more.
Don't comment-out tests cases that don't pass
(unless they cause an error, preventing the rest of the program from running).
-
Any code which results in syntax errors
will generally not earn more than 50%
of the points-possible.
For grading, I will ignore any commented-out code.
-
Format well
(in particular, each open-paren should be preceded by a space).
home—lectures—recipe—exams—hws—D2L—breeze (snow day; distance)