Pessoal, estou montando um programinha aki, mas quando eu rodo o programa, cadastro o cliente depois vejo o relatorio, dai os dados aparecem de forma desordenada. Ex: Nome: Rua José da Silva. Ja tentei ver aonde esta o problema mas nao achei.
Outra duvida que tenho é se no método delCli() da classe Principal eu fiz certo?
Peço a ajuda de vocês.
Segue as 3 classes que desenvolvi até agora.
public class Pessoa { //Definição da classe Pessoa
private String nme,
nasc,
cpf,
end,
cid,
bai,
est,
cep,
tel,
cel,
email;
public Pessoa(){ //Método contrutor padrão
this.nme = "";
this.nasc = "";
this.cpf = "";
this.end = "";
this.cid = "";
this.bai = "";
this.est = "";
this.cep = "";
this.tel = "";
this.cel = "";
this.email = "";
}
public Pessoa(String nme, String nasc, String cpf, String end, String cid,
String bai, String est, String cep, String tel, String cel,
String email){
this.nme = nme;
this.nasc = nasc;
this.cpf = cpf;
this.end = end;
this.cid = cid;
this.bai = bai;
this.est = est;
this.cep = cep;
this.tel = tel;
this.cel = cel;
this.email = email;
}
public void setNme(String nme){
this.nme = nme;
}
public String getNme(){
return this.nme;
}
public void setNasc(String nasc){
this.nasc = nasc;
}
public String getNasc(){
return this.nasc;
}
public void setCpf(String cpf){
this.cpf = cpf;
}
public String getCpf(){
return this.nasc;
}
public void setEnd(String end){
this.end = end;
}
public void setCid(String cid){
this.cid = cid;
}
public String getCid(){
return this.cid;
}
public void setBai(String bai){
this.bai = bai;
}
public String getBai(){
return this.bai;
}
public void setEst(String est){
this.est = est;
}
public String getEst(){
return this.est;
}
public void setCep(String cep){
this.cep = cep;
}
public String getCep(){
return this.cep;
}
public void setTel(String tel){
this.tel = tel;
}
public String getTel(){
return this.tel;
}
public void setCel(String cel){
this.cel = cel;
}
public String getCel(){
return this.cel;
}
public void setEmail(String email){
this.email = email;
}
public String getEmail(){
return this.email;
}
}
public class Cliente extends Pessoa{ //Definição da classe Cliente
private String dataCad,
nmeEmp,
foneEmp,
siteEmp,
adcEmp;
public Cliente(){ //Método contrutor padrão
super();
this.dataCad = "";
this.nmeEmp = "";
this.foneEmp = "";
this.siteEmp = "";
this.adcEmp = "";
}
public Cliente(String nme, String nasc, String cpf, String end, String cid,
String bai, String est, String cep, String tel, String cel,
String email, String datCad, String nmeEmp, String foneEmp, String siteEmp,
String adcEmp){
super(nme, nasc, cpf, end, cid, bai, est, cep, tel, cel, email);
this.dataCad = datCad;
this.nmeEmp = nmeEmp;
this.foneEmp = foneEmp;
this.siteEmp = siteEmp;
this.adcEmp = adcEmp;
}
public void setNmeEmp(String nmeEmp){
this.nmeEmp = nmeEmp;
}
public String getNmeEmp(){
return this.nmeEmp;
}
public void setFoneEmp(String foneEmp){
this.foneEmp = foneEmp;
}
public String getFoneEmp(){
return this.foneEmp;
}
public void setSiteEmp(String siteEmp){
this.siteEmp = siteEmp;
}
public String getSiteEmp(){
return this.siteEmp;
}
public void setAdcEmp(String adcEmp){
this.adcEmp = adcEmp;
}
public String getAdcEmp(){
return this.adcEmp;
}
}
import java.util.ArrayList;
import javax.swing.JOptionPane;
public class Principal {
private ArrayList armazena;
Cliente cli = null;
public Principal(){ // Método construtor padrão
armazena = new ArrayList();
}
public void CadCli(){ //Método para cadastrar Cliente
String datCad = JOptionPane.showInputDialog("Data Cadastro: ");
String nme = JOptionPane.showInputDialog("Nome Cliente: ");
String nasc = JOptionPane.showInputDialog("Nascimento Cliente: ");
String cpf = JOptionPane.showInputDialog("CPF Cliente: ");
String end = JOptionPane.showInputDialog("Endereço Cliente: ");
String cid = JOptionPane.showInputDialog("Cidade Cliente: ");
String bai = JOptionPane.showInputDialog("Bairro Cliente: ");
String est = JOptionPane.showInputDialog("UF Cliente: ");
String cep = JOptionPane.showInputDialog("CEP Cliente: ");
String tel = JOptionPane.showInputDialog("Telefone Cliente: ");
String cel = JOptionPane.showInputDialog("Celular Cliente: ");
String email = JOptionPane.showInputDialog("Email Cliente: ");
String nmeEmp = JOptionPane.showInputDialog("Nome Empresa: ");
String foneEmp = JOptionPane.showInputDialog("Telefone Empresa: ");
String siteEmp = JOptionPane.showInputDialog("Site Empresa: ");
String adcEmp = JOptionPane.showInputDialog("Informações Adicionais: ");
cli = new Cliente(nme, nasc, cpf, end, cid, bai, est,
cep, tel, cel, email, datCad, nmeEmp, foneEmp, siteEmp, adcEmp);
armazena.add(cli);
}
public void delCli(){ //Método para excluir Cliente
if (cli == null)
JOptionPane.showMessageDialog(null, "ERRO: LISTA VAZIA!" +
JOptionPane.ERROR_MESSAGE);
else
{
String nme = JOptionPane.showInputDialog("Nome Completo: ");
String cpf = JOptionPane.showInputDialog("CPF: ");
for (int i = 0; i < armazena.size(); i++){
cli = (Cliente)armazena.get(i);
if (cli.getNme().equals(nme) && cli.getCpf().equals(cpf)){
cli = null;
JOptionPane.showMessageDialog(null, "Cliente Removido com sucesso!"
+ JOptionPane.INFORMATION_MESSAGE);
break;
}
}
}
}
public void RelCli(){
if (cli == null)
JOptionPane.showMessageDialog(null, "ERRO: LISTA VAZIA!" +
JOptionPane.ERROR_MESSAGE);
else
{
for (int i = 0; i < armazena.size(); i++)
cli = (Cliente)armazena.get(i);
JOptionPane.showMessageDialog(null, "Nome: " + cli.getNme() +
"\nNascimento: " + cli.getNasc() + "\nCPF: " + cli.getCpf() +
"\nCidade: " + cli.getCid() + "\nEstado: " + cli.getEst() +
"\nCelular: " + cli.getCel() + "\nEmail: " + cli.getEmail() +
"\nEmpresa: " + cli.getNmeEmp() + "\nFone Empresa: " +
cli.getFoneEmp());
}
}
public static void main(String[] args){
Principal principal = new Principal();
int op = 0;
String nme,
cpf;
do
{
op = Integer.parseInt(JOptionPane.showInputDialog("1 - Cadastrar Cliente\n2 - Excluir Cliente\n3 - Relatório de Clientes\n10 - Sair"));
switch(op)
{
case 1: principal.CadCli(); break;
case 3: principal.RelCli();
}
}
while (op != 10);
}
}
Segue é codigo, dicas eu aceito tambem…XD
