@leonardobg7 escreveu:
Pessoal, preciso de ajuda nesse projeto. Não estou conseguindo implementar a classe locação. Não consigo interagir com as outras classes.
Eu preciso pegar o nome do cliente, o carro e depois calcular um valor. Custei à entender ArrayList e preciso saber como chamar as duas classes Carro e Cliente e juntar na locação.
Não quero o código pronto, porém não sei como resolver.
Quem puder ajudar, agradeço muito.
Classe Cliente:
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package trabalhoprog; /** * * @author leonardo */ public class Cliente { private long Codigo; private String Nome; private String Logradouro; private long Numero; private String Bairro; private String Municipio; private String Estado; private long CEP; private long Telefone; public Cliente(long Codigo, String Nome, String Logradouro, long Numero, String Bairro, String Municipio, String Estado, long CEP, long Telefone) { this.Codigo = Codigo; this.Nome = Nome; this.Logradouro = Logradouro; this.Numero = Numero; this.Bairro = Bairro; this.Municipio = Municipio; this.Estado = Estado; this.CEP = CEP; this.Telefone = Telefone; } public long getCodigo() { return Codigo; } public String getNome() { return Nome; } public String getLogradouro() { return Logradouro; } public long getNumero() { return Numero; } public String getBairro() { return Bairro; } public String getMunicipio() { return Municipio; } public String getEstado() { return Estado; } public long getCEP() { return CEP; } public long getTelefone() { return Telefone; } public void setCodigo(long Codigo) { this.Codigo = Codigo; } public void setNome(String Nome) { this.Nome = Nome; } public void setLogradouro(String Logradouro) { this.Logradouro = Logradouro; } public void setNumero(long Numero) { this.Numero = Numero; } public void setBairro(String Bairro) { this.Bairro = Bairro; } public void setMunicipio(String Municipio) { this.Municipio = Municipio; } public void setEstado(String Estado) { this.Estado = Estado; } public void setCEP(long CEP) { this.CEP = CEP; } public void setTelefone(long Telefone) { this.Telefone = Telefone; } }
Classe Carro:
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package trabalhoprog; /** * * @author leonardo */ public class Cliente { private long Codigo; private String Nome; private String Logradouro; private long Numero; private String Bairro; private String Municipio; private String Estado; private long CEP; private long Telefone; public Cliente(long Codigo, String Nome, String Logradouro, long Numero, String Bairro, String Municipio, String Estado, long CEP, long Telefone) { this.Codigo = Codigo; this.Nome = Nome; this.Logradouro = Logradouro; this.Numero = Numero; this.Bairro = Bairro; this.Municipio = Municipio; this.Estado = Estado; this.CEP = CEP; this.Telefone = Telefone; } public long getCodigo() { return Codigo; } public String getNome() { return Nome; } public String getLogradouro() { return Logradouro; } public long getNumero() { return Numero; } public String getBairro() { return Bairro; } public String getMunicipio() { return Municipio; } public String getEstado() { return Estado; } public long getCEP() { return CEP; } public long getTelefone() { return Telefone; } public void setCodigo(long Codigo) { this.Codigo = Codigo; } public void setNome(String Nome) { this.Nome = Nome; } public void setLogradouro(String Logradouro) { this.Logradouro = Logradouro; } public void setNumero(long Numero) { this.Numero = Numero; } public void setBairro(String Bairro) { this.Bairro = Bairro; } public void setMunicipio(String Municipio) { this.Municipio = Municipio; } public void setEstado(String Estado) { this.Estado = Estado; } public void setCEP(long CEP) { this.CEP = CEP; } public void setTelefone(long Telefone) { this.Telefone = Telefone; } }
Classe Empresa:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package trabalhoprog;import java.util.*; import java.util.ArrayList; /** * * @author leonardo */ public class Empresa { Scanner Ler = new Scanner(System.in); ArrayList<Cliente> listaDeClientes = new ArrayList<>(); ArrayList<Carro> listaDeCarros = new ArrayList<>(); int k = 0; long codigo = 1, numero, telefone, CEP; String nome, logradouro, bairro, municipio, estado; String nomeAlt; String marca, cor, cc, categoria; Double preco; public void AddCliente() { /* System.out.print("Digite o nome: "); nome = Ler.nextLine(); System.out.print("Digite o logradouro: "); logradouro = Ler.nextLine(); System.out.print("Digite o numero: "); numero = Ler.nextLong(); Ler.nextLine(); System.out.print("Digite o bairro: "); bairro = Ler.nextLine(); System.out.print("Digite o municipio: "); municipio = Ler.nextLine(); System.out.print("Digite o estado: "); estado = Ler.nextLine(); System.out.print("Digite o cep: "); CEP = Ler.nextLong(); Ler.nextLine(); System.out.print("Digite o telefone: "); telefone = Ler.nextLong(); Ler.nextLine(); listaDeClientes.add(new Cliente (codigo,nome,logradouro,numero,bairro,municipio,estado,CEP,telefone)); */ //PREGUIÇA DE FICAR DIGITANDO DADO TODA HORA QUE EU FOR TESTAR "-- listaDeClientes.add(new Cliente(555, "nome teste", "rua treta", 666, "fim do mundo", "contagem das abóboras", "MG", 335566, 66666)); } public void AlteracaoCliente() { System.out.print("\nDigite o nome do cliente em que o(s) dado(s) serão alterados: "); nomeAlt = Ler.nextLine(); for (int i = 0; i < listaDeClientes.size(); ++i) { if (listaDeClientes.get(i).getNome().equals(nomeAlt)) {//verifica no vetor o departamento igual ao digitado e seleciona ele while (k < 666) { System.out.println("\n\tSelecione uma opção a seguir:\n"); System.out.println("1-Nome\n2-Logradouro\n3-Número\n4-Bairro\n5-Município\n6-Estado\n7-CEP\n8-Telefone\n9-Sair\n"); System.out.print("Digite uma opção: "); int op1 = Ler.nextInt(); Ler.nextLine();//corrigir bug System.out.println(""); ///quebra de linha adicional switch (op1) { case 1: System.out.print("Digite o novo nome: "); nome = Ler.nextLine(); listaDeClientes.get(i).setNome(nome); break; case 2: System.out.print("Digite o novo logradouro: "); logradouro = Ler.nextLine(); listaDeClientes.get(i).setLogradouro(logradouro); break; case 3: System.out.print("Digite o novo numero: "); numero = Ler.nextLong(); listaDeClientes.get(i).setNumero(numero); break; case 4: System.out.print("Digite o novo bairro: "); bairro = Ler.nextLine(); listaDeClientes.get(i).setBairro(bairro); break; case 5: System.out.print("Digite o novo municipio: "); municipio = Ler.nextLine(); listaDeClientes.get(i).setMunicipio(municipio); break; case 6: System.out.print("Digite o novo Estado: "); estado = Ler.nextLine(); listaDeClientes.get(i).setEstado(estado); break; case 7: System.out.print("Digite o novo CEP: "); CEP = Ler.nextLong(); listaDeClientes.get(i).setCEP(CEP); break; case 8: System.out.print("Digite o novo telefone: "); telefone = Ler.nextLong(); listaDeClientes.get(i).setTelefone(telefone); break; case 9: k = 667; break; } } } } } public void RemoverCliente() { System.out.print("\nDigite o nome do cliente que será EXCLUÍDO: "); nomeAlt = Ler.nextLine(); for (int i = 0; i < listaDeClientes.size(); ++i) { if (listaDeClientes.get(i).getNome().equals(nomeAlt)) {//verifica no vetor o departamento igual ao digitado e seleciona ele listaDeClientes.remove(listaDeClientes.get(i)); } } } public void AddCarro() { /* System.out.print("Digite a marca: "); marca = Ler.nextLine(); System.out.print("Digite a cor: "); cor = Ler.nextLine(); System.out.print("Digite a CC: "); cc = Ler.nextLine(); System.out.print("Digite a categoria: "); categoria = Ler.nextLine(); System.out.print("Digite o preço: "); preco = Ler.nextDouble(); listaDeCarros.add(new Carro (marca,cor,cc,categoria,preco)); */ //PREGUIÇA DE FICAR DIGITANDO DADO TODA HORA QUE EU FOR TESTAR "-- listaDeCarros.add(new Carro("Tesla", "Vermelho", "1.4", "Sedan", 666.55)); listaDeCarros.add(new Carro("Ford", "Preto", "2.0", "Hatch", 100.00)); } public void AlteracaoCarro() { System.out.print("\nDigite a MARCA do carro que deseja alterar: "); String nomeMarca = Ler.nextLine(); for (int i = 0; i < listaDeCarros.size(); i++) { if (listaDeCarros.get(i).getMarca().equals(nomeMarca)) {//verifica no vetor o departamento igual ao digitado e seleciona ele while (k < 666) { System.out.println("\n1-Marca\n2-Cor\n3-CC\n4-Categoria\n5-Preço\n6-Sair"); System.out.print("\nSelecione o dado a ser alterado ou digite 6 para SAIR: "); int op5 = Ler.nextInt(); Ler.nextLine(); System.out.println(""); switch (op5) { case 1: System.out.print("Digite a nova MARCA: "); marca = Ler.nextLine(); listaDeCarros.get(i).setMarca(marca); break; case 2: System.out.print("Digite a nova COR: "); cor = Ler.nextLine(); listaDeCarros.get(i).setCor(cor); break; case 3: System.out.print("Digite a CC: "); cc = Ler.nextLine(); listaDeCarros.get(i).setCC(cc); break; case 4: System.out.print("Digite a nova CATEGORIA: "); categoria = Ler.nextLine(); listaDeCarros.get(i).setCategoria(categoria); break; case 5: System.out.print("Digite o novo PREÇO: "); preco = Ler.nextDouble(); listaDeCarros.get(i).setPreco(preco); break; case 6: k = 667; break; } } } } } public void RemoverCarro() { System.out.print("\nDigite a MARCA do carro que deseja REMOVER: "); String nomeMarca = Ler.nextLine(); for (int i = 0; i < listaDeCarros.size(); ++i) { if (listaDeCarros.get(i).getMarca().equals(nomeMarca))//verifica no vetor o departamento igual ao digitado e seleciona ele { listaDeCarros.remove(listaDeCarros.get(i)); } } } public void ExibirClientes() { for (int n = 0; n < listaDeClientes.size(); n++) { System.out.println("Cliente:" + listaDeClientes.get(n).getNome()); System.out.println("Código:" + listaDeClientes.get(n).getCodigo()); System.out.println("Logradouro:" + listaDeClientes.get(n).getLogradouro()); System.out.println("Número:" + listaDeClientes.get(n).getNumero()); System.out.println("Bairro:" + listaDeClientes.get(n).getBairro()); System.out.println("Municipio:" + listaDeClientes.get(n).getMunicipio()); System.out.println("Estado:" + listaDeClientes.get(n).getEstado()); System.out.println("CEP:" + listaDeClientes.get(n).getCEP()); System.out.println("Telefone:" + listaDeClientes.get(n).getTelefone()); System.out.println(""); } } public void ExibirCarros() { for (int n = 0; n < listaDeCarros.size(); n++) { System.out.println("Marca:" + listaDeCarros.get(n).getMarca()); System.out.println("Cor:" + listaDeCarros.get(n).getCor()); System.out.println("CC:" + listaDeCarros.get(n).getCC()); System.out.println("Categoria:" + listaDeCarros.get(n).getCategoria()); System.out.println("Preço:" + listaDeCarros.get(n).getPreco()); System.out.println(""); } } }
Classe Locação:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package trabalhoprog;/** * * @author leonardo */ public class Locação { private Cliente clientes; private Carro Carros; private String Data; private Double ValorDev; public void locacao (String clientes){ } public Cliente getClientes() { return clientes; } public Carro getCarros() { return Carros; } public String getData() { return Data; } public Double getValorDev() { return ValorDev; } }
Classe Main:
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package trabalhoprog; import java.util.*; /** * * @author leonardo */ public class TrabalhoProg { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Empresa Loccar = new Empresa(); Scanner Ler = new Scanner(System.in); int op1, op2, op3 = 0, i, j = 0; while (j < 666) { System.out.println("\n\n\tSeja bem-vindo(a) a LocCar!\n\nSelecione uma das opções abaixo:\n"); //Pensa em um nome mais criativo System.out.println("1-Cliente\n2-Carro\n3-Locação\n4-Sair"); System.out.print("\nDigite a opção: "); i = 0; op1 = Ler.nextInt(); while (i < 666) { if (op1 == 1) { //Cliente System.out.println("\n\tCLIENTE - Digite uma das opções abaixo:\n"); System.out.println("1-Cadastro\n2-Alteração/Excluir\n3-Relatório\n4-Voltar ao Menu principal"); System.out.print("\nDigite a opção: "); op2 = Ler.nextInt(); switch (op2) { case 1: while (op3 <= 1) { Loccar.AddCliente(); System.out.println("\nDeseja adicionar mais um cliente?\n1-SIM\n2-NÃO\n"); System.out.print("Digite a opção: "); op3 = Ler.nextInt(); if (op3 == 1); //Desse jeito o ciclo permanence, já que nada é alterado if (op3 >= 2) { op3 = 3; //encerra o ciclo } } break; case 2: System.out.println("\n1-Alterar o dado de um cliente\n2-Remover um cliente\n"); System.out.print("Digite a opção: "); int op4 = Ler.nextInt(); if (op4 == 1) { Loccar.AlteracaoCliente(); } if (op4 == 2) { Loccar.RemoverCliente(); } break; case 3: System.out.println("\n\tRELATÓRIO DE TODOS OS CARROS CADASTRADOS:\n"); Loccar.ExibirClientes(); break; case 4: i = 667; break; //Voltar ao menu principal } } if (op1 == 2) { //Carro System.out.println("\n\tCARRO - Digite uma das opções abaixo:\n"); System.out.println("1-Cadastro\n2-Alteração/Excluir\n3-Relatório\n4-Voltar ao Menu principal"); System.out.print("\nDigite a opção:"); op2 = Ler.nextInt(); switch (op2) { case 1: op3 = 0;//garante que a varáivel seja zero while (op3 <= 1) { Loccar.AddCarro(); System.out.println("\nDeseja adicionar mais um CARRO?\n\n1-SIM\n2-NÃO\n"); System.out.print("Digite a opção: "); op3 = Ler.nextInt(); if (op3 == 1); //Desse jeito o ciclo permanence, já que nada é alterado if (op3 >= 2) { op3 = 3; //encerra o ciclo } } break; case 2: System.out.println("\n1-Alterar o dado de um CARRO\n2-Remover um CARRO\n"); System.out.print("Digite a opção: "); int op4 = Ler.nextInt(); if (op4 == 1) { Loccar.AlteracaoCarro(); } if (op4 == 2) { Loccar.RemoverCarro(); } break; case 3: System.out.println("\n\tRELATÓRIO DE TODOS OS CLIENTES CADASTRADOS:\n"); Loccar.ExibirCarros(); break; case 4: i = 667; break;//Voltar ao menu principal } } if (op1 == 3) { //Locação System.out.println("\nLOCAÇÃO - Digite uma das opções abaixo:"); System.out.println("1-Empréstimo\n2-Devolução\n3-Relatório\n4-Voltar ao Menu principal"); System.out.print("\nDigite a opção:"); op2 = Ler.nextInt(); switch (op2) { case 1: //função cadastro case 2: //função Alteração case 3: //função Relatório case 4: i = 667; //Voltar ao menu principal } } if (op1 == 4) { //Sair j = 667; i = 667; System.out.println("\n\tOBRIGADO PELA VISITVA, VOLTE SEMPRE!"); } } } } }
Mensagens: 10
Participantes: 3