-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTracinhos.java
More file actions
105 lines (91 loc) · 2.87 KB
/
Copy pathTracinhos.java
File metadata and controls
105 lines (91 loc) · 2.87 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import java.util.Arrays;
public class Tracinhos implements Cloneable
{
private char texto [];
public Tracinhos (int qtd) throws Exception
{
// verifica se qtd n�o � positiva, lan�ando uma exce��o.
// instancia this.texto com um vetor com tamanho igual qtd.
// preenche this.texto com underlines (_).
if(qtd < 0)
throw new Exception("ERRO");
this.texto = new char[qtd];
for(int i = 0; i < qtd; i++){
this.texto[i] = '_';
}
}
public void revele (int posicao, char letra) throws Exception
{
// verifica se posicao � negativa ou ent�o igual ou maior
// do que this.texto.length, lan�ando uma exce��o.
// armazena a letra fornecida na posicao tambem fornecida
// do vetor this.texto
for(int i = 0; i < texto.length; i++){
if(posicao < 0 || posicao >= texto.length)
throw new Exception("ERRO");
}
texto[posicao] = letra;
}
public boolean isAindaComTracinhos ()
{
// percorre o vetor de char this.texto e verifica
// se o mesmo ainda contem algum underline ou se ja
// foram todos substituidos por letras; retornar true
// caso ainda reste algum underline, ou false caso
// contrario
for (char x : this.texto)
{
if(x == '_')
return true;
}
return false;
}
public String toString ()
{
// retorna um String com TODOS os caracteres que h�
// no vetor this.texto, intercalados com espa�os em
// branco
String resultado = "";
for(char value : this.texto){
resultado += value + " ";
}
return resultado;
}
public boolean equals (Object obj)
{
// verificar se this e obj possuem o mesmo conte�do, retornando
// true no caso afirmativo ou false no caso negativo
if(this == obj) return true;
if(obj==null) return false;
if(this.getClass() != obj.getClass()) return false;
if(this.equals(obj)) return true;
return true;
}
public int hashCode ()
{
int ret = 6;
ret = 3 * ret + Arrays.hashCode(this.texto);
if (ret<0) ret=-ret;
return ret;
}
public Tracinhos (Tracinhos t) throws Exception // construtor de c�pia
{
// intanciar this.texto um vetor com o mesmo tamanho de t.texto //TERMINAR
// e copilar o conte�do de t.texto para this.texto
if (t==null)
throw new Exception("Tracinhos ausente");
this.texto= t.texto;
}
public Object clone ()
{
// retornar uma copia de this
Tracinhos ret=null;
try
{
ret = new Tracinhos(this);
}
catch (Exception erro)
{} // não ocorrerá
return ret;
}
}