Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

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,

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.

Step by Step Solution

3.39 Rating (165 Votes )

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Applying International Financial Reporting Standards

Authors: Keith Alfredson, Ken Leo, Ruth Picker, Paul Pacter, Jennie Radford Victoria Wise

3rd edition

730302121, 978-0730302124

More Books

Students explore these related Computer Network questions