Game of Cricket: Write classes CricketGame, Player, Match and MatchController and any class thet they think is required. Write a random function which returns 0,1,2,3,4,5,6 or W. That is for every ball it says runs or wicket. Match controller to take 2 teams and uses the sequence of random function calls and prints the results. Run multiple times and print results" please create your individual repository on git every time I give an enhancement on the project.. it should be checked in as a new branch
All the classes with only instance variable and no methods are put into /beans. All the functions that operate on objects and call different functions are put into /controller. /util has all the class with only static functions, i.e. we only use the class name to use the functions defined in them. /main holds the class that has the main function written.
- Beans
- Match
- Player
- Team
- Controller
- MatchController
- Main
- CricketApplication
- Util
- GetRunsOrWicket
- PlayerUtil
- PlayMatch
- Result
- Role
- StartMatchUtil
- TeamUtil
- Toss
- Two teams are assumed, India and Australia.
- A
toss()is done to decide who goes first. - In the second inning when the batting team scores more than what the previous team made, the game ends and the second team wins.
- A HashMap is used to keep track of the scores.
-1represents Wicket and0-6represent runs - When a team looses 10 wickets, turn for that team is over.
- For generating runs and wicket, a
betterRandomfunction is used that generates random number based on different probabilities inO(n)time. Such as the chances of a team earning 5 runs is very rare, so it probability is set to 5%.Wicket: 5% probability0: 30% probability1: 20% probability2: 18% probability3: 15% probability4: 8% probability5: 1% probability6: 3% probability
- Spring Boot 2.2.3
- Java 13
- InteliJ IDEA
- Gradle
Import the project with InteliJ IDEA. Let the gradle build. Import all the dependencies. Then go the CricketApplication which holds the main class. The results are returned as HTML responses. Use a browser to test the API. The application runs on port: 8080.
If using PostMan use the Preview mode to see the response.
localhost:8080/: Greeting message.localhost:8080/match: Start the game.