An over consists of six balls bowled by one bowler to one batsman and the outcome of
Question:
An over consists of six balls bowled by one bowler to one batsman and the outcome of each ball can be one of 0 runs, 1 run, 2 runs, 3 runs, 5 runs, illegal, or out. The batsman’s state must be updated after each of the balls, but the bowler's state is only adjusted after an illegal ball.
Write a function updateBatsman that takes the outcome of a ball and the batsman’s state, and returns the batsman’s updated state.
Write a function updateBowler that takes the outcome of a ball and the bowler’s state, and returns the bowler’s updated state. Remember that the bowler’s state is only affected by illegal balls.
The code below shows how the functions should be called and the desired output.
ballOutcomes <- c("run0", "run1", "run2", "run3", "run5", "illegal", "out")
# test batsman
playerScoreBoard(updateBatsman("run0", playerA), header = TRUE)
Name 0s 1s 2s 3s 5s X Out Tot
T Smith 1 0 0 0 0 0 0 0
playerScoreBoard(updateBatsman("run1", playerA))
T Smith 0 1 0 0 0 0 0 1
playerScoreBoard(updateBatsman("out", playerA))
T Smith 0 0 0 0 0 0 1 -5
playerScoreBoard(updateBatsman("illegal", playerA))
T Smith 0 0 0 1 0 0 0 3
# test bowler
playerScoreBoard(updateBowler("run0", playerA))
T Smith 0 0 0 0 0 0 0 0
playerScoreBoard(updateBowler("run5", playerA))
T Smith 0 0 0 0 0 0 0 0
playerScoreBoard(updateBowler("illegal", playerA))
T Smith 0 0 0 0 0 1 0 -1
Show that your code produces the same results.
Applying International Financial Reporting Standards
ISBN: 978-0730302124
3rd edition
Authors: Keith Alfredson, Ken Leo, Ruth Picker, Paul Pacter, Jennie Radford Victoria Wise