[Question]
ROBOTIC CRICKET MATCH
you should write a program that
simulate an automatic cricket match between India and Sri Lanka. The focus is
the usage of Java Thread Constructs. Each Innings happens within its thread.
You decide the 11 members of each team and provide two lists to the program.
The first team is represented as team 1 and second team as team 2. You have to
generate a random number for toss and if the number is between 0 and 1, team 1
bats first- else, if the number is between 1 and 2, then team 2 bats first. The
batting happens by starting a thread. Each ball bowled is via a random number
generator (that generates number rounded off, between 0 and 7). If the number
is 0, batsman is out. If the number is 1, run is 1, number is 2, run is 2,
number is 3, run is 3, number is 4, run is 4, number is 5, run is 5, number is
6, run is 6. If the number is exactly 7, then it is an extra 1 run and if it is
0, batsman is out). You have to do this until 10 batsmen get out in 1 team. The
final score sheet will show as follows. Then you have to start another thread
and do the same as above. The match ends either when the second team batsmen
are out, with scores lesser than team 1 (team 1 wins), scores are tied (match
is tied) and as soon score is greater than team 1 (team 2 wins). Each over is
for 6 balls, if extra happens (number 7), 1 run is awarded and 1 extra ball is
bowled. Extra run and Extra Ball is not part of batsman's account. Total Overs
are 10. (T101 Match)
(No Need to Take Care of Changing
Batsman Strike If Score is 1, 3 or 5. No Need to Record Bowling Figures of the
Bowler in the Solution. No Need to Take Care Separately of Wide, No Balls,
Byes, Leg Byes. There are No Free-Hits!).
[Sample Input]
(No Input is Required)
[Sample Output]
Toss Won By SL (Team 0)
Team 0 (SL) is Batting First
India-Batting Scoresheet
Rohit Sharma 1,4,3,6,1,0=15 (6)
Shubman Gill 0=0 (1)
Virat Kohli 4,6,1,0=11 (4)
KL Rahul 3,1,4,0=8 (4)
Ishan Kishan 6,6,6,4,0 = 22 (5)
Hardik Pandya 0 = 0 (1)
Ravindra Jadeja 6,0 = 6 (2)
Washington Sundar 1,3,0 = 4 (3)
Kuldeep Yadav 1,2,3,4,0=10 (5)
Mohammed Siraj 0 = 0 (1)
Jasprit Bumrah Did Not Bat
Extras 1, 1, 1, 1, 1, 5
Total Score 81 in 5.2 overs
Sri Lanka - Batting Scoresheet
Pathum Nissanka 0=0(1)
Kusal Perera 0=0 (1)
Kusal Mendis 1,0=1(2)
Sadeera Samarawickrama 1,1,0=2 (3)
Charith Asalanka 2,0=2(2)
Dhananjaya de Silva 4,4,0 = 8 (3)
Dasun Shanaka (c) 1,4,6,0=11 (4)
DunithWellalage 6,6,0=12 (3)
Dushan Hemantha 0=0 (1)
Pramod Madushan 1,0=1(2)
Matheesha Pathirana Did Not Bat
Extras 1, 1=2
Total Score 39 in 3.4 overs
Match Result: Team 0 (India) Won
By 42 Runs
Today's Date: 17/09/2023
Areas : Core Java, Logic, Longer
Problem Solving, Understanding Requirements, Java Multi- Threading, Java Async
Execution, Java Collections.
Points to Note
200 Marks will be Awarded to this
Question. Pass Marks are at 120. You have to understand if you do not use any
threading or async task execution in java, you will be awarded at the maximum
120- 140 marks, provided that your logic is working correctly. The Remaining
60-80 marks are given to showcase/prove your skills in Java Multi-Threading or
Async Task Execution. You have to start the first thread for the first innings
while the main program runs, then once the innings is complete, you have to
make sure that the main program understands that. Similar way you have to start
the second thread and note there might be shared objects or shared data to use.
Please make sure you also understand/demonstrate thread safety.
[Explanation of Solution]
This Java program simulates a
cricket match between India and Sri Lanka using multi-threading. It begins by
randomly determining which team bats first and then runs the innings in
separate threads.
Each ball bowled is generated with
a random number from 0 to 7, where 0 means the batsman is out, 1 to 6 represent
the runs scored, and 7 signifies an extra run. The match consists of two
innings, and the program keeps track of batsmen, their scores, and extras.
The match result is determined
based on the scores of both teams. If the second team's score is lower than the
first team's, team 1 wins. If the scores are tied, it's a tie, and if the
second team scores more, team 2 wins.
The program showcases multi-threading concepts to simulate the cricket match and provides a detailed scorecard at the end.