Baixe o app para aproveitar ainda mais
Esta é uma pré-visualização de arquivo. Entre para ver o arquivo original
aplica�oes_locais/src/Local6/Main.java /* * 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 Local6; import javax.swing.JOptionPane; /** * * @author luis */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { String cpf = JOptionPane.showInputDialog("Informe o CPF: "); String cnpj = JOptionPane.showInputDialog("Informe o CNPJ: "); Resolucao cc = new Resolucao(); if (cc.validarCPF(cpf) == true) { System.out.println("CPF " + cpf + " Válido!"); } else { System.out.println("CPF " + cpf + " Inválido!"); } if (cc.validarCNPJ(cnpj) == true) { System.out.println("CNPJ " + cpf + " Válido!"); } else { System.out.println("CNPJ " + cpf + " Inválido!"); } } } aplica�oes_locais/src/Local6/Resolucao.java /* * 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 Local6; import java.util.InputMismatchException; /** * * @author luis */ public class Resolucao implements ICPF_CNPJ{ @Override public boolean validarCPF(String CPF) { // considera-se erro CPF's formados por uma sequencia de numeros iguais if (CPF.equals("00000000000") || CPF.equals("11111111111") || CPF.equals("22222222222") || CPF.equals("33333333333") || CPF.equals("44444444444") || CPF.equals("55555555555") || CPF.equals("66666666666") || CPF.equals("77777777777") || CPF.equals("88888888888") || CPF.equals("99999999999") || (CPF.length() != 11)) return(false); char dig10, dig11; int sm, i, r, num, peso; // "try" - protege o codigo para eventuais erros de conversao de tipo (int) try { // Calculo do 1o. Digito Verificador sm = 0; peso = 10; for (i=0; i<9; i++) { // converte o i-esimo caractere do CPF em um numero: // por exemplo, transforma o caractere '0' no inteiro 0 // (48 eh a posicao de '0' na tabela ASCII) num = (int)(CPF.charAt(i) - 48); sm = sm + (num * peso); peso = peso - 1; } r = 11 - (sm % 11); if ((r == 10) || (r == 11)) dig10 = '0'; else dig10 = (char)(r + 48); // converte no respectivo caractere numerico // Calculo do 2o. Digito Verificador sm = 0; peso = 11; for(i=0; i<10; i++) { num = (int)(CPF.charAt(i) - 48); sm = sm + (num * peso); peso = peso - 1; } r = 11 - (sm % 11); if ((r == 10) || (r == 11)) dig11 = '0'; else dig11 = (char)(r + 48); // Verifica se os digitos calculados conferem com os digitos informados. if ((dig10 == CPF.charAt(9)) && (dig11 == CPF.charAt(10))) return(true); else return(false); } catch (InputMismatchException erro) { return(false); } } public static String imprimeCPF(String CPF) { return(CPF.substring(0, 3) + "." + CPF.substring(3, 6) + "." + CPF.substring(6, 9) + "-" + CPF.substring(9, 11)); } @Override public boolean validarCNPJ(String CNPJ) { char dig13, dig14; int sm, i, r, num, peso; sm = 0; peso = 2; for (i = 11; i >= 0; i--) { num = (int) (CNPJ.charAt(i) - 48); sm = sm + (num * peso); peso = peso + 1; if (peso == 10) { peso = 2; } } r = sm % 11; if ((r == 0) || (r == 1)) { dig13 = '0'; } else { dig13 = (char) ((11 - r) + 48); sm = 0; peso = 2; for (i = 12; i >= 0; i--) { num = (int) (CNPJ.charAt(i) - 48); sm = sm + (num * peso); peso = peso + 1; if (peso == 10) { peso = 2; } } } r = sm % 11; if ((r == 0) || (r == 1)) { dig14 = '0'; } else { dig14 = (char) ((11 - r) + 48); } if ((dig13 == CNPJ.charAt(12)) && (dig14 == CNPJ.charAt(13))) { return (true); } else { return (false); } } } aplica�oes_locais/src/Local6/ICPF_CNPJ.java /* * 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 Local6; /** * * @author luis */ public interface ICPF_CNPJ { public boolean validarCPF(String CPF); public boolean validarCNPJ(String CNPJ); } aplica�oes_locais/src/Local2/IMatematica.java /* * 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 Local2; /** * * @author luis */ public interface IMatematica { public double somar(double a, double b); public double subtrair(double a, double b); public double multiplicar(double a, double b); public double dividir(double a, double b); public double[][] somar(double a[][], double b[][]); public double[][] subtrair(double a[][], double b[][]); public double[][] multiplicar(double a[][], double b[][]); public double[][] multiplicar(double a[][], double b); } aplica�oes_locais/src/Local2/Main.java /* * 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 Local2; import Local1.IStringUtil; import Local1.StringUtilImp1; import javax.swing.JOptionPane; /** * * @author luis */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { StringMatematica sm = new StringMatematica(); System.out.println("Soma de 2 Numeros:" + sm.somar(1.1, 2.2)); System.out.println("Subtrir 2 Numeros:" + sm.subtrair(1.1, 2.2)); System.out.println("Multiplicar 2 Numeros:" + sm.multiplicar(1.1, 2.2)); System.out.println("Dividir 2 Numeros:" + sm.dividir(1.1, 2.2)); } } aplica�oes_locais/src/Local2/StringMatematica.java /* * 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 Local2; /** * * @author luis */ public class StringMatematica implements IMatematica{ @Override public double somar(double a, double b) { double soma = a+b; return soma; } @Override public double subtrair(double a, double b) { double subtrair = a-b; return subtrair; } @Override public double multiplicar(double a, double b) { double multiplicar = a*b; return multiplicar; } @Override public double dividir(double a, double b) { double dividir = a/b; return dividir; } @Override public double[][] somar(double[][] a, double[][] b) { double resultado[][] = null; for (int i = 0; i < a.length; i++) { for (int j = 0; j < b.length; j++) { resultado[i][j] = a[i][j] + b[i][j]; } } return resultado; } @Override public double[][] subtrair(double[][] a, double[][] b) { double resultado[][] = null; for (int i = 0; i < a.length; i++) { for (int j = 0; j < b.length; j++) { resultado[i][j] = a[i][j] - b[i][j]; } } return resultado; } @Override public double[][] multiplicar(double[][] a, double[][] b) { double resultado [][] = null; for (int i = 0; i < a.length; i++) { for (int j = 0; j < b.length; j++) { resultado[i][j] = a[i][j] * b[i][j]; } } return resultado; } @Override public double[][] multiplicar(double[][] a, double b) { double resultado [][] = null; for (int i = 0; i < a.length; i++) { for (int j = 0; j < i; j++) { resultado[i][j] = a[i][j] * b; } } return resultado; } } aplica�oes_locais/src/Local7/DNSImpl.java /* * 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 Local7; import java.util.ArrayList; import java.util.List; /** * * @author luis */ public class DNSImpl implements IDNS{ List<DNS> tabelaDNS; public DNSImpl(){ tabelaDNS = new ArrayList(); } @Override public String bind(String dominio, String IP, int porta) { for (DNS registro : tabelaDNS) { if (registro.getDominio().equals(dominio)) { return "Erro. Dominio já registrado!"; } } tabelaDNS.add( new DNS(dominio,IP,porta)); return "Dominio registrado com sucesso"; } @Override public String lookup(String dominio) { for (DNS registro : tabelaDNS) { if (registro.getDominio().equals(dominio)) { return registro.getIp()+":"+registro.getPorta(); } } return "Erro. Dominio não encontrado"; } @Override public String unbind(String dominio) { for (DNS registro : tabelaDNS) { if (registro.getDominio().equals(dominio)) { tabelaDNS.remove(registro); return "Dominio removido com sucesso!"; } } return "Erro. Dominio não encontrado!"; } } aplica�oes_locais/src/Local7/DNS.java /* * 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 Local7; import java.util.Objects; /** * * @author luis */ public class DNS { private String dominio; private String ip; private int porta; public DNS() { } public DNS(String dominio, String ip, int porta) { this.dominio = dominio; this.ip = ip; this.porta = porta; } public String getDominio() { return dominio; } public void setDominio(String dominio) { this.dominio = dominio; } public String getIp() { return ip; } public void setIp(String ip) { this.ip = ip; } public int getPorta() { return porta; } public void setPorta(int porta) { this.porta = porta; } @Override public int hashCode() { int hash = 7; hash = 59 * hash + Objects.hashCode(this.dominio); hash = 59 * hash + Objects.hashCode(this.ip); hash = 59 * hash + this.porta; return hash; } @Override public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final DNS other = (DNS) obj; if (!Objects.equals(this.dominio, other.dominio)) { return false; } return true; } @Override public String toString() { return "DNS:" + "\nDominio - " + dominio + "\nIp - " + ip + "\nPorta " + porta + '.'; } } aplica�oes_locais/src/Local7/IDNS.java /* * 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 Local7; /** * * @author luis */ public interface IDNS { public String bind(String dominio, String IP, int porta); public String lookup(String dominio); public String unbind(String dominio); } aplica�oes_locais/src/Local7/Main.java /* * 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 Local7; /** * * @author luis */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { IDNS registroDNS =new DNSImpl(); String resposta = ""; resposta = registroDNS.bind("pb.utfpr.edu.br", "200.134.80.36", 80); System.out.println("Resposta:" +resposta); resposta = registroDNS.bind("pb.utfpr.edu.br", "200.134.80.36", 80); System.out.println("Resposta:" +resposta); resposta = registroDNS.bind("google.com.br", "74.75.90.141", 80); System.out.println("Resposta:" +resposta); resposta = registroDNS.lookup("google.com.br"); System.out.println("Resposta:" +resposta); resposta = registroDNS.unbind("google.com.br"); System.out.println("Resposta:" +resposta); resposta = registroDNS.lookup("google.com.br"); System.out.println("Resposta:" +resposta); } } aplica�oes_locais/nbproject/project.xml org.netbeans.modules.java.j2seproject Aplicaçoes_Locais aplica�oes_locais/nbproject/project.properties annotation.processing.enabled=true annotation.processing.enabled.in.editor=false annotation.processing.processor.options= annotation.processing.processors.list= annotation.processing.run.all.processors=true annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output build.classes.dir=${build.dir}/classes build.classes.excludes=**/*.java,**/*.form # This directory is removed when the project is cleaned: build.dir=build build.generated.dir=${build.dir}/generated build.generated.sources.dir=${build.dir}/generated-sources # Only compile against the classpath explicitly listed here: build.sysclasspath=ignore build.test.classes.dir=${build.dir}/test/classes build.test.results.dir=${build.dir}/test/results # Uncomment to specify the preferred debugger connection transport: #debug.transport=dt_socket debug.classpath=\ ${run.classpath} debug.test.classpath=\ ${run.test.classpath} # Os arquivos em build.classes.dir que devem ser exclu\u00eddos do jar de distribui\u00e7\u00e3o dist.archive.excludes= # This directory is removed when the project is cleaned: dist.dir=dist dist.jar=${dist.dir}/Aplica_oes_Locais.jar dist.javadoc.dir=${dist.dir}/javadoc excludes= includes=** jar.compress=false javac.classpath= # Space-separated list of extra javac options javac.compilerargs= javac.deprecation=false javac.processorpath=\ ${javac.classpath} javac.source=1.8 javac.target=1.8 javac.test.classpath=\ ${javac.classpath}:\ ${build.classes.dir} javac.test.processorpath=\ ${javac.test.classpath} javadoc.additionalparam= javadoc.author=false javadoc.encoding=${source.encoding} javadoc.noindex=false javadoc.nonavbar=false javadoc.notree=false javadoc.private=false javadoc.splitindex=true javadoc.use=true javadoc.version=false javadoc.windowtitle= main.class=br.edu.utfpr.aplocais.exer1.Aplica\u00e7oes_Locais manifest.file=manifest.mf meta.inf.dir=${src.dir}/META-INF mkdist.disabled=false platform.active=default_platform run.classpath=\ ${javac.classpath}:\ ${build.classes.dir} # Space-separated list of JVM arguments used when running the project. # You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. # To set system properties for unit tests define test-sys-prop.name=value: run.jvmargs= run.test.classpath=\ ${javac.test.classpath}:\ ${build.test.classes.dir} source.encoding=UTF-8 src.dir=src test.src.dir=test aplica�oes_locais/nbproject/build-impl.xml Must set src.dir Must set test.src.dir Must set build.dir Must set dist.dir Must set build.classes.dir Must set dist.javadoc.dir Must set build.test.classes.dir Must set build.test.results.dir Must set build.classes.excludes Must set dist.jar Must set javac.includes No tests executed. Must set JVM to use for profiling in profiler.info.jvm Must set profiler agent JVM arguments in profiler.info.jvmargs.agent Must select some files in the IDE or set javac.includes To run this application from the command line without Ant, try: java -jar "${dist.jar.resolved}" Must select one file in the IDE or set run.class Must select one file in the IDE or set run.class Must select one file in the IDE or set debug.class Must select one file in the IDE or set debug.class Must set fix.includes This target only works when run from inside the NetBeans IDE. Must select one file in the IDE or set profile.class This target only works when run from inside the NetBeans IDE. This target only works when run from inside the NetBeans IDE. This target only works when run from inside the NetBeans IDE. Must select one file in the IDE or set run.class Must select some files in the IDE or set test.includes Must select one file in the IDE or set run.class Must select one file in the IDE or set applet.url Must select some files in the IDE or set javac.includes Some tests failed; see details above. Must select some files in the IDE or set test.includes Some tests failed; see details above. Must select some files in the IDE or set test.class Must select some method in the IDE or set test.method Some tests failed; see details above. Must select one file in the IDE or set test.class Must select one file in the IDE or set test.class Must select some method in the IDE or set test.method Must select one file in the IDE or set applet.url Must select one file in the IDE or set applet.url aplica�oes_locais/nbproject/genfiles.properties build.xml.data.CRC32=63c80dca build.xml.script.CRC32=a4cc312c build.xml.stylesheet.CRC32=8064a381@1.75.2.48 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. nbproject/build-impl.xml.data.CRC32=63c80dca nbproject/build-impl.xml.script.CRC32=3c55bbb8 nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.75.2.48 aplica�oes_locais/build/classes/.netbeans_update_resources aplica�oes_locais/build/classes/.netbeans_automatic_build aplica�oes_locais/build/classes/Local1/IStringUtil.class aplica�oes_locais/build/classes/Local1/StringUtilImp1.class aplica�oes_locais/build/classes/Local1/Main.class aplica�oes_locais/build/classes/Local5/IHoraCerta.class aplica�oes_locais/build/classes/Local5/Hora.class aplica�oes_locais/build/classes/Local5/Main.class aplica�oes_locais/build/classes/Local4/IConversor.class aplica�oes_locais/build/classes/Local4/Main.class aplica�oes_locais/build/classes/Local4/ConversorIMpl1.class aplica�oes_locais/src/Local1/Main.java package Local1; /** * * @author luis */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { IStringUtil str = new StringUtilImp1(); System.out.println("Ecoar:" + str.ecoar("Teste")); System.out.println("Inverter:" + str.inverter("Teste")); System.out.println("Inverter Palavra:" + str.inverterPalavra("Teste 123")); } } aplica�oes_locais/src/Local1/IStringUtil.java /* * 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 Local1; /** * * @author luis */ public interface IStringUtil { public String ecoar(String str); public String inverter(String str); public String inverterPalavra(String str); public boolean isPalindroma(String str); public boolean isPangram(String str); } aplica�oes_locais/src/Local1/StringUtilImp1.java package Local1; /** * * @author luis */ public class StringUtilImp1 implements IStringUtil { @Override public String ecoar(String str) { return str; } @Override public String inverter(String str) { String reverse = new StringBuffer(str).reverse().toString(); return reverse; } @Override public String inverterPalavra(String str) { String alterada = ""; String[] word = str.split(" "); for (int i = 0; i < word.length; i++) { StringBuilder sb = new StringBuilder(word[i]); sb.reverse(); word[i] = sb.toString(); alterada = alterada + " " + word[i]; } return alterada; } @Override public boolean isPalindroma(String str) { if (str.equals(inverter(str))) { return true; } else { return false; } } @Override public boolean isPangram(String str) { boolean resposta = false; String alfabeto = "abcdefghijklmnopqrstuvxywz"; for (int i = 0; i < alfabeto.length(); i++) { if (str.contains(String.valueOf(alfabeto.charAt(i)))) { resposta = true; } else { resposta = false; break; } } return resposta; } } Aplica�oes_Locais/manifest.mf Manifest-Version: 1.0 X-COMMENT: Main-Class will be added automatically by build Aplica�oes_Locais/build.xml Builds, tests, and runs the project Aplicaçoes_Locais. aplica�oes_locais/build/classes/Local6/Resolucao.class aplica�oes_locais/build/classes/Local6/Main.class aplica�oes_locais/build/classes/Local6/ICPF_CNPJ.class aplica�oes_locais/src/Local3/Main.java package Local3; import javax.swing.JOptionPane; public class Main { public static void main(String[] args) { int valor = Integer.valueOf(JOptionPane.showInputDialog("Informe o valor: ")); Conversor c = new Conversor(); System.out.println("Valor " + valor + " depois da conversão para ACM: " + c.convertACMtoDEC(valor)); } } aplica�oes_locais/src/Local3/IConversor.java package Local3; public interface IConversor { public int convertACMtoDEC(int a); } aplica�oes_locais/src/Local3/Conversor.java package Local3; public class Conversor implements IConversor { public int fatorial(int num) { int fatorial = 1; for (int i = 1; i <= num; i++) { fatorial = fatorial * i; } return fatorial; } @Override public int convertACMtoDEC(int a) { int cont = Integer.toString(a).length(); int j = cont; String numeroString = Integer.toString(a); int[] array = new int[Integer.parseInt(numeroString)]; int resultado = 0; int separado = 0; for (int i = 0; i < cont; i++) { separado = Integer.parseInt(numeroString.substring(i, i + 1)); array[i] = separado; } for (int i = 0; i < cont; i++) { int fat = fatorial(j); j--; System.out.println(array[i]); resultado = resultado + (array[i] * fat); } return resultado; } } aplica�oes_locais/build/classes/Local8/ProdutoIMPL.class aplica�oes_locais/build/classes/Local8/Main.class aplica�oes_locais/build/classes/Local8/Icadastro.class aplica�oes_locais/build/classes/Local8/Produto.class aplica�oes_locais/build/classes/Local7/Main.class aplica�oes_locais/build/classes/Local7/DNSImpl.class aplica�oes_locais/build/classes/Local7/IDNS.class aplica�oes_locais/build/classes/Local7/DNS.class aplica�oes_locais/build/classes/Local3/Main.class aplica�oes_locais/build/classes/Local3/Conversor.class aplica�oes_locais/build/classes/Local3/IConversor.class aplica�oes_locais/nbproject/private/private.xml aplica�oes_locais/nbproject/private/private.properties compile.on.save=true user.properties.file=/home/luis/.netbeans/8.0/build.properties aplica�oes_locais/src/Local4/IConversor.java /* * 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 Local4; import java.util.HashMap; /** * * @author luis */ public interface IConversor { public double converter(String de, String para, double valor); public void adicionarCotacao(String moeda, double cotacao); public void removerCotacao(String moeda); public HashMap<String, Double> listarCotacoes(); } aplica�oes_locais/src/Local4/Main.java package Local4; import java.util.Iterator; import java.util.Map.Entry; /** * * @author luis */ public class Main { public static void main(String[] args) { IConversor conversor = new ConversorIMpl1(); conversor.adicionarCotacao("Real", 1.00); conversor.adicionarCotacao("Dolar", 3.00); conversor.adicionarCotacao("Euro", 3.90); conversor.adicionarCotacao("Peso", 0.30); System.out.println("10 Reais em dolares:" + conversor.converter("Real", "Dolar", 10.0)); System.out.println("/** Lista de Cotaçoês**/"); Iterator it = conversor.listarCotacoes().entrySet().iterator(); while(it.hasNext()){ Entry cotacao = (Entry) it.next(); System.out.println(cotacao.getKey() +" - " + cotacao.getValue()); } } } aplica�oes_locais/src/Local4/ConversorIMpl1.java package Local4; import java.util.HashMap; /** * * @author luis */ public class ConversorIMpl1 implements IConversor{ private HashMap<String, Double> tabelaConversao; public ConversorIMpl1(){ tabelaConversao = new HashMap<String,Double>(); } @Override public double converter(String de, String para, double valor) { return tabelaConversao.get(de)/tabelaConversao.get(para)*valor; } @Override public void adicionarCotacao(String moeda, double cotacao) { tabelaConversao.put(moeda, cotacao); } @Override public void removerCotacao(String moeda) { tabelaConversao.remove(moeda); } @Override public HashMap<String, Double> listarCotacoes() { return tabelaConversao; } } aplica�oes_locais/build/classes/Local2/StringMatematica.class aplica�oes_locais/build/classes/Local2/Main.class aplica�oes_locais/build/classes/Local2/IMatematica.class aplica�oes_locais/src/Local5/Hora.java /* * 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 Local5; import java.text.SimpleDateFormat; import java.util.Date; import java.util.GregorianCalendar; /** * * @author luis */ public class Hora implements IHoraCerta{ @Override public String dataAtual() { SimpleDateFormat dataFormatada = new SimpleDateFormat("dd/MM/yyyy"); Date data = new Date(); return dataFormatada.format(data); } @Override public String horaAtual() { SimpleDateFormat horaFormadata = new SimpleDateFormat("HH:mm:ss"); Date data = new Date(); return horaFormadata.format(data); } } aplica�oes_locais/src/Local5/Main.java /* * 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 Local5; /** * * @author luis */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { Hora h = new Hora(); System.out.println(h.dataAtual()); System.out.println(h.horaAtual()); } } aplica�oes_locais/src/Local5/IHoraCerta.java /* * 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 Local5; /** * * @author luis */ public interface IHoraCerta { public String dataAtual(); public String horaAtual(); } aplica�oes_locais/src/Local8/Main.java /* * 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 Local8; /** * * @author luis */ public class Main { /** * @param args the command line arguments */ private Icadastro c; public static void main(String[] args) { Main p = new Main(); } public Main() { c = new ProdutoIMPL(); iniciar(); } public void iniciar() { Produto p = new Produto(); p.setCodigo(1); p.setNome("Televisão"); p.setSaldo(10); p.setValor(1750.00); Produto p1 = new Produto(); p1.setCodigo(1); p1.setNome("Rádio"); p1.setSaldo(5); p1.setValor(1000.00); System.out.println(c.insert(p)); System.out.println(c.insert(p1)); System.out.println(c.delete(p)); System.out.println(c.find(2)); } } aplica�oes_locais/src/Local8/ProdutoIMPL.java /* * 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 Local8; import java.util.ArrayList; import java.util.List; /** * * @author luis */ public class ProdutoIMPL implements Icadastro { private List<Produto> listaProduto; ProdutoIMPL() { this.listaProduto = new ArrayList<>(); } @Override public String insert(Produto produto) { for (Produto p : listaProduto) { if (p.getCodigo() == produto.getCodigo()) { return "Erro: produto já cadastrado!"; } } listaProduto.add(produto); return "Ok. Produto cadastrado!"; } @Override public String delete(Produto produto) { for (Produto p : listaProduto) { if (p.getCodigo() == produto.getCodigo()) { listaProduto.remove(produto); return "Ok. Produto removido!"; } } return "Erro: Produto não encontrado!"; } @Override public String find(int codigo) { for (Produto p : listaProduto) { if (p.getCodigo() == codigo) { return "-------------------------------------------------------\n" + "Produto: " + p.getNome() + "\nValor: " + p.getValor() + "\nSaldo: " + p.getSaldo() + "\n-------------------------------------------------------"; } } return "Erro: produto não existe!"; } } aplica�oes_locais/src/Local8/Icadastro.java /* * 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 Local8; /** * * @author luis */ public interface Icadastro { public String insert(Produto produto); public String delete(Produto produto); public String find(int codigo); } aplica�oes_locais/src/Local8/Produto.java /* * 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 Local8; import java.util.Objects; /** * * @author luis */ public class Produto { private int codigo; private String nome; private double valor; private int saldo; public Produto() { } public Produto(int codigo, String nome, double valor, int saldo) { this.codigo = codigo; this.nome = nome; this.valor = valor; this.saldo = saldo; } public int getCodigo() { return codigo; } public void setCodigo(int codigo) { this.codigo = codigo; } public String getNome() { return nome; } public void setNome(String nome) { this.nome = nome; } public double getValor() { return valor; } public void setValor(double valor) { this.valor = valor; } public int getSaldo() { return saldo; } public void setSaldo(int saldo) { this.saldo = saldo; } @Override public int hashCode() { int hash = 3; hash = 29 * hash + this.codigo; hash = 29 * hash + Objects.hashCode(this.nome); hash = 29 * hash + (int) (Double.doubleToLongBits(this.valor) ^ (Double.doubleToLongBits(this.valor) >>> 32)); hash = 29 * hash + this.saldo; return hash; } @Override public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final Produto other = (Produto) obj; if (this.codigo != other.codigo) { return false; } return true; } }
Compartilhar