Cricket Scoreboard
Runs, wickets, and overs from a stream of deliveries — the design work is pinning the extras and over rules precisely.
Scoring rules
normal— addrunsto the total and count one legal ball.wide— addruns + 1(one penalty run plus any runs taken); it is not a legal ball.noball— addruns + 1(one penalty run plus runs off the delivery); it is not a legal ball.wicket— addruns(runs completed on the delivery still count, e.g. a run-out), increment the wicket tally, and count one legal ball.- An over is 6 legal balls.
oversreports"<completedOvers>.<legalBallsInCurrentOver>"— e.g. after 7 legal balls it reads1.1; wides and no-balls never advance it. - All values are cumulative from the start of the innings, and the class is fully deterministic.
API to implement
Implement the class Scoreboard. The I/O driver is already written in the starter code — it parses the command script below and calls your methods. You only implement the class.
| Command | Returns | Behavior |
|---|---|---|
| ball <runs> <event> | — | Record one delivery worth runs runs with outcome event ∈ {normal, wide, noball, wicket}. See the scoring rules below. |
| score | int | Total runs scored so far (including extras). |
| wickets | int | Number of wickets fallen. |
| overs | string | Overs bowled as "<completedOvers>.<legalBallsInCurrentOver>" (6 legal balls = 1 over). |
Input format
The first line contains Q, the number of operations. Each of the next Q lines is one command as listed above. String arguments contain no spaces.
Output format
For each command with a non-void return, print its result on its own line, in order. The driver does this for you — your methods just return values.
This is a design problem: the hidden tests exercise edge cases and interaction sequences, not performance tricks. Model the state cleanly and the tests will pass.
Sample cases
9
ball 0 wide
ball 0 noball
ball 4 normal
score
overs
ball 1 wide
score
overs
wickets6
0.1
8
0.1
011
ball 1 normal
ball 2 normal
ball 0 normal
ball 4 normal
ball 1 normal
ball 0 wicket
overs
score
wickets
ball 6 normal
overs1.0
8
1
1.1