-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCarta.java
More file actions
37 lines (30 loc) · 909 Bytes
/
Carta.java
File metadata and controls
37 lines (30 loc) · 909 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
public class Carta {
private int numero;
public Carta(int numero) {
this.numero = numero;
}
public int getNumero() {
return numero;
}
public int calcularPontuacao() {
int pontos = 1;
if (numero % 10 == 5) { // Cartas terminadas com o dígito 5 valem 1 ponto extra
pontos++;
}
if (numero % 10 == 0) { // Cartas múltiplas de 10 valem 2 pontos extras
pontos += 2;
}
if (temDigitosRepetidos(numero)) { // Cartas com dois dígitos repetidos valem 4 pontos extras;
pontos += 4;
}
return pontos;
}
private boolean temDigitosRepetidos(int num) {
String numStr = String.valueOf(num);
return numStr.length() == 2 && numStr.charAt(0) == numStr.charAt(1);
}
@Override
public String toString() {
return "Carta " + numero;
}
}