Small tennis simulation in Java
Hello, I am a new programmer and I have Several questions about how to implement object oriented features in my tennis simulation being written in Java. Index of /apliques/2007/2/ProjetoTenis/src
First I will tell how my simulation works so that you all can understand better what I need to do, how to do it and especially how to do it in an object oriented way (can have some generic programming too)
This is how the program works
I am doing a little tennis program in which I implement the simulation of a game of a tennis match based on random number generation and probabilities. For example, it chooses a number between 1 to 2, and if the result is 1, the player hits the first serve. If not, then the second one.
Then, when he hits any of the two serves, it sorts a number between 1 to 10. In the first serve case, if the number is anything between 1 to 8, the server wins the point. In the second serve case, the server wins the point if the value choosed is anything between 1 to 5.
I have three big classes, one that has the main method and creates an object that represents a tennis match.
This object calls for a method of the class "Game", the class responsible for 'managing' a game from a tennis match.
For now the only thing this "Game" class is doing, is holding the method responsable for controlling the serves, that as was said in the above paragrapher, are the responsables for deciding who is going to win a point. The method "saque" (serve in english) chooses a serve and then send it to a certain method of the "Pontos" (points) class to select who winned the point.This class contains three methods, each one for one of the three possibilities: first serve in, second serve in and double fault. When the winner of the point is choosed, I would like it to return the two variables that represent the points that each player will have after the point is finished,
back to method "saque" (serve) of the Game class.
This brings me to the first problem: methods cannot return two values. So, can I create an object composed of two fields and return it? If I can, can you guys show how to do it?. If not, what you suggest?. I need to return them because I intend to create in the "Game" class, another method, one that will control the game, or in another words, finish the program when a player collects enough points to win the game.
Then in the "game" class, I would like to send these two values, whether they will be in an object or in another form to the "control" method that I intend to create in the same class. This brings to the second question which is: when these points will be returned, should I create this "control method" in the same class and send the values to it, or should I do something completely different to allow bigger modularization?.
And the last question comes to the surface due to the fact that the point count changes during the game. The way it is now. at each new point 15points will be given to the variable that represents the score of one of the players.
How should I change this value according to occasion? Should I create an object of the type "Point" to do this?
Thanks for all the suggestions and recomendations.