In this assignment, we will delve into Object-Oriented Programming (OOP) with a simple but appealing mini project. This mini project would be very enjoyable for Harry Potter fans, but if you haven't watched the film, don't worry; you don't need any pre-knowledge about this film to do this assignment. You can also use this link to read about Quidditch rules.
Your assignment is a bit different from the real game. You won't need to implement any GUI or complex logic; the whole logic will be handled by chance. Don't worry!
We have two teams. Each team has a keeper, a seeker, 3 chasers, and 2 beaters. You can read about each role's responsibilities in the above link, so let's talk about implementing the project. Each of these roles has a name, number, and each one has a method called isSuccessful
. The chance of success varies for each one. Let's start with the keeper.
The keeper has a 70% chance to save a hanging goal.
The seeker has a 5% chance to find the golden snitch.
The chaser has a 30% chance to score a goal.
The beater has a 40% chance to stop chasers.
- Create a class for each role (Keeper, Seeker, etc.).
- Create a class called
Player
and make all roles inherit this class. - Create an interface called
Success
and put the methodisSuccessful
inside it. Don't forget to implement this interface with all of your roles. What's next?
- Create a class for
Team
. This class contains players of your team (1 Keeper, 1 Seeker, 3 Chasers, and 2 Beaters) and the number of goals, which is zero at the beginning of the game. - It has a method called
setGoal
, and after calling it, the number of goals increases by one. However, this method is private. - Also, we have another method called
play
. After calling this method, the team will start playing the game, and if the conditions are met, then thesetGoal
method will be called.
When the keeper of the team is successful in saving the goal, at least one beater is successful, and at least two chasers are successful in the match, then the team will score a goal.
When a seeker of a team finds the golden snitch, the team will get 150 scores and will win the match. Otherwise, the team with the most goals will win the match.
After you've created the Team
class, it's time for the Match
class. In this class, you will need to create two teams initially. Then, you create a method called start
. This method will start the game.
The game consists of 100 rounds. In each round, both teams will play, and after finishing the game, the scores of both teams will be shown, and also the winning team will be shown as the winner. Don't forget that the game can also end in a draw.
The final class you need is the MyApp
class. In this class, you will create a match and start that match in your main
method. Run the program and enjoy it!