1
When I call the method setNomedoMetodo()
in another class, even with it instantiated, appears:
The method setNaipe(String[]) is Undefined for the type Deck.
I can’t put a value on that method. And I can’t mix the cards either. Follow an excerpt from the code:
Carta Class
public class Carta {
private String[] naipe;
private String[] nome;
//Métodos especiais
public String[] getNaipe() {
return naipe;
}
public void setNaipe(String[] naipe) {
this.naipe = naipe;
}
public String[] getNome() {
return nome;
}
public void setNome(String[] nome) {
this.nome = nome;
}
}
Deck class
package Jogo;
import java.util.Random;
public class Baralho {
Carta[] cartas = new Carta[52];
String[] naipes = {"Copas", "Espada", "Ouros", "Paus"};
String[] nomes = {"As", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"};
String coringa;
Random aleatorio = new Random();
public Baralho() {
int cont = 0;
for (String naipe : naipes) {
for (String nome : nomes) {
Carta cartas = new Carta();
this.setNaipe(naipes);
this.setNome(nomes);
this.cartas[cont] = cartas;
this.embaralha(naipes);
cont++;
}
this.setNaipe(coringa);
}
System.out.println(cartas);//Teste
}
public void embaralha(String[] carta) {
aleatorio.naipes();
}
public void daCarta() {
for (int i = 0; i < cartas.length; i++) {
if (cartas[0] == null) {
break;
}else {
System.out.println(cartas[0]);
}
}
}
public boolean temCarta() {
boolean TouF = true;
for (int i = 0; i < cartas.length; i++) {
if (cartas[i] != null) {
TouF = false;
}else {
TouF = true;
}
}
return TouF;
}
public void imprime() {
for (int i = 0; i < cartas.length; i++) {
System.out.println(cartas[i]);
}
}
}
Add the full deck class.
– user28595
I added the whole class
– Marcos Paulo S. Rezende