Created
October 31, 2012 02:55
-
-
Save tiagox/3984542 to your computer and use it in GitHub Desktop.
Clase que representa un game de tenis.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Clase que representa un game de tenis. | |
*/ | |
public class Game { | |
private int puntosSaque = 0; | |
private int puntosRecepcion = 0; | |
/** | |
* pre : el Game no ha terminado. | |
* post: registra un punto para el saque. | |
*/ | |
public void anotarPuntoSaque() { | |
if (!this.termino()) { | |
this.puntosSaque += 1; | |
} | |
} | |
/** | |
* pre : el Game no ha terminado. | |
* post: registra un punto para la recepción. | |
*/ | |
public void anotarPuntoRecepcion() { | |
if (!this.termino()) { | |
this.puntosRecepcion += 1; | |
} | |
} | |
/** | |
* post: devuelve si el Game terminó. | |
*/ | |
public boolean termino() { | |
/* | |
* Gana quien llegue primero a hacer 4 puntos (15, 30, 40, game) | |
* y mantenga una diferencia de 2 puntos con su adversario. De lo contrario | |
* el Game sigue hasta que, uno de los jugadores, logre una diferencia de 2 | |
* puntos. | |
*/ | |
return (this.puntosSaque >= 4 && this.puntosSaque - this.puntosRecepcion > 1) || | |
(this.puntosRecepcion >= 4 && this.puntosRecepcion - this.puntosSaque > 1); | |
} | |
/** | |
* pre: el Game ha terminado. | |
* post: devuelve si el saque ganó el Game. | |
*/ | |
public boolean ganoSaque() { | |
return this.puntosSaque > this.puntosRecepcion; | |
} | |
/** | |
* pre: el Game ha terminado. | |
* post: devuelve si la recepción ganó el Game. | |
*/ | |
public boolean ganoRecepcion() { | |
return this.puntosRecepcion > this.puntosSaque; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment