When I call the setNomedoMetodo()
method in another class, even with it instantiated, it appears:
The method setNaipe (String []) is undefined for the type Deck.
I can not put a value in this method. Nor can I mix the cards. Here's a snippet of code:
Charter 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;
}
}
Class Deck
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]);
}
}
}