diff --git a/clientes.txt b/clientes.txt index c121e61..05b8f10 100644 --- a/clientes.txt +++ b/clientes.txt @@ -1,4 +1,6 @@ Tiago Silva,195572,913538232,250422@epvc.pt,228389992,500.0 manel,779820,987654321,manel@epvc.pt,123456789,60.0 Tony Eric Wilson,720726,967761691,tony@mail.pt,228389992,1000.0 -Eric,390298,938624267,e@e.pt,228389992,654783.0 +Eric,390298,938624267,e@e.pt,228389992,654803.0 +Tomás,507712,967761691,tiago@mail.com,228389992,385.0 +Wilson,755137,909876543,ftyj@eptp.com,228389992,700.0 diff --git a/faturas.txt b/faturas.txt index ca2de3a..bd162c7 100644 --- a/faturas.txt +++ b/faturas.txt @@ -1 +1,11 @@ ouwefh, 934384261, rua alexandre de morais, 38, 25/11/2012, Cinquenta euros, valor, ilhbv +Vendeiro, 913538232, Póvoa de Varzim, 25/05/2023, Duzentos e cinquenta e seis euros, valor, Eric +Vendeiro, 946823523, Póvoa de Varzim, 24/07/2023, Trezentos e cinquenta e quatro euros, valor, Eric +Vendeiro, 940736325, Vila do Conde, 23/07/2023, Quatrocentos e vinte e cinco euros e cinquenta e seis cêntimos, valor, Eric +tiago, 912345678, Porto, 23/07/2023, Cento e vinte e três euros e quarenta e cinco cêntimos, valor, Eric +Vendeiro, 987654321, Porto, 11/07/2023, Quatrocentos euros e dois cêntimos, valor, Wilson +Vendeiro, 987654321, Porto, 23/04/2023, Duzentos euros e um cêntimo, valor, Wilson +vendeiro, 987654321, Porto, 23/07/2023, Duzentos euros, valor, Wilson +e, 987654321, e, 23/07/2023, Duzentos euros e dois cêntimos, valor, Wilson +e, 987654321, e, , Duzentos euros, valor, e +e, 987654321, e, 23/07/2023, Duzentos euros e dois cêntimos, valor, Wilson diff --git a/src/main/java/com/mycompany/mavenproject25/Mavenproject25.java b/src/main/java/com/mycompany/mavenproject25/Mavenproject25.java index 6fd1503..053f7ef 100644 --- a/src/main/java/com/mycompany/mavenproject25/Mavenproject25.java +++ b/src/main/java/com/mycompany/mavenproject25/Mavenproject25.java @@ -266,7 +266,8 @@ private static void menuClienteLogado(String[] dadosCliente) { "║ ▸ 3 Depositar ║\n" + "║ ▸ 4 Levantar dinheiro ║\n" + "║ ▸ 5 Cheque ║\n" + - "║ ▸ 6 Sair ║\n" + + "║ ▸ 6 Cambio ║\n" + + "║ ▸ 7 Sair ║\n" + "╚═════════════════════════════════════════╝\n", "SEU SALDO: " + saldo); @@ -277,7 +278,7 @@ private static void menuClienteLogado(String[] dadosCliente) { mostrarDadosCliente(dadosCliente); break; case 2: - saldo = transferirDinheiro(dadosCliente[1], saldo); + saldo = transferirDinheiro(dadosCliente[2], saldo); atualizarSaldoCliente(dadosCliente[1], saldo); break; case 3: @@ -289,7 +290,9 @@ private static void menuClienteLogado(String[] dadosCliente) { atualizarSaldoCliente(dadosCliente[1], saldo); break; case 5 : cheque(); - case 6: + break; + case 6 : moeda(); + case 7: sair = true; System.out.println("A sair da conta..."); break; @@ -311,13 +314,13 @@ private static void menuClienteLogado(String[] dadosCliente) { System.out.println ("╚════════════════════════════════════════╝\n"); } - private static double transferirDinheiro(String idOrigem, double saldoOrigem) { + private static double transferirDinheiro(String telOrigem, double saldoOrigem) { Scanner scanner = new Scanner(System.in); - System.out.print("Digite o ID do cliente destinatário: "); - String idDestino = scanner.nextLine(); + System.out.print("Digite o número de Telefone do destinatário: "); + String telDestino = scanner.nextLine(); - if (idDestino.equals(idOrigem)) { + if (telDestino.equals(telOrigem)) { System.out.println("Não pode transferir para si mesmo!"); return saldoOrigem; } @@ -334,22 +337,11 @@ private static void menuClienteLogado(String[] dadosCliente) { System.out.println("Saldo insuficiente!"); return saldoOrigem; } - - String[] dadosDestino = procurarClientePorId(idDestino); - - if (dadosDestino == null) { - System.out.println("Cliente destinatário não encontrado!"); - return saldoOrigem; - } - - double saldoDestino = Double.parseDouble(dadosDestino[5]) + valor; - saldoOrigem -= valor; - - atualizarSaldoCliente(idDestino, saldoDestino); - atualizarSaldoCliente(idOrigem, saldoOrigem); + saldoOrigem = saldoOrigem - valor; + atualizarSaldoCliente(telOrigem, saldoOrigem); System.out.printf("Transferência de "+valor+" realizada com sucesso!\n", valor); - System.out.printf("Novo saldo:"+valor+"\n", saldoOrigem); + return saldoOrigem; } @@ -466,7 +458,7 @@ private static void menuAdmin() { + "║ ▸ 2 Procurar cliente ║\n" + "║ ▸ 3 Editar dados de cliente ║\n" + "║ ▸ 4 Remover cliente ║\n" - + "║ ▸ 5 Estatísticas do sistema ║\n" + + "║ ▸ 5 Estatisticas ║\n" + "║ ▸ 6 Sair ║\n" + "╚════════════════════════════════════════╝\n"); @@ -485,9 +477,7 @@ private static void menuAdmin() { case 4: removerCliente(); break; - case 5: - mostrarEstatisticas(); - break; + case 5:mostrarEstatisticas(); case 6: sair = true; break; @@ -687,14 +677,14 @@ private static void mostrarEstatisticas() { double saldoMedio = saldoTotal / numClientes; System.out.println("\n╔════════════════════════════════════════════════════════════════╗"); - System.out.println( "║ ESTATÍSTICAS DO SISTEMA ║"); - System.out.println( "╠════════════════════════════════════════════════════════════════╣"); - System.out.printf( "║\n", "Total de clientes: " + numClientes); - System.out.printf( "║\n", String.format("Saldo total do banco: ", saldoTotal)); - System.out.printf( "║\n", String.format("Saldo médio por cliente: ", saldoMedio)); - System.out.printf( "║\n", String.format("Cliente com maior saldo: ", clienteSaldoMaximo, saldoMaximo)); - System.out.printf( "║\n", String.format("Cliente com menor saldo: ", clienteSaldoMinimo, saldoMinimo)); - System.out.println( "╚════════════════════════════════════════════════════════════════╝\n"); + System.out.println("║ ESTATÍSTICAS DO SISTEMA ║"); + System.out.println("╠════════════════════════════════════════════════════════════════╣"); + System.out.printf("║ Total de clientes: %d%44s%n", numClientes, "║"); + System.out.printf("║ Saldo total do banco: %.2f%33s%n", saldoTotal, "║"); + System.out.printf("║ Saldo médio por cliente: %.2f%30s%n", saldoMedio, "║"); + System.out.printf("║ Cliente com maior saldo: %s (%.2f)%23s%n", clienteSaldoMaximo, saldoMaximo, "║"); + System.out.printf("║ Cliente com menor saldo: %s (%.2f)%26s%n", clienteSaldoMinimo, saldoMinimo, "║"); + System.out.println("╚════════════════════════════════════════════════════════════════╝\n"); } private static void atualizarClienteCompleto(String[] dados) { @@ -1007,10 +997,11 @@ public static void editarDinheiroCliente() { System.out.println("║ ID gerado: " + idTitular); String nif; - do { + System.out.print("║ Introduza NIF (9 dígitos): "); nif = scanner.nextLine(); + while (!verificarNIF(nif) || nif.isEmpty());{ if (!verificarNIF(nif)) { System.out.println("║ NIF inválido! Deve ter 9 dígitos válidos."); } else if (nifJaExiste(nif)) { @@ -1018,13 +1009,14 @@ public static void editarDinheiroCliente() { System.out.println("║ Por favor, insira um NIF diferente."); nif = ""; } - } while (!verificarNIF(nif) || nif.isEmpty()); + } String telefone; System.out.print("║ Introduza telefone (9 dígitos): "); telefone = scanner.nextLine(); + while (telefone.isEmpty() || telefone.length() != 9 || !telefone.matches("\\d+")){ if (telefone.length() != 9 || !telefone.matches("\\d+")) { System.out.println("║ Telefone inválido! Deve ter 9 dígitos."); } else if (telefoneJaExiste(telefone)) { @@ -1032,7 +1024,7 @@ public static void editarDinheiroCliente() { System.out.println("║ Por favor, insira um telefone diferente."); telefone = ""; } - while (telefone.isEmpty() || telefone.length() != 9 || !telefone.matches("\\d+")); + } String email; @@ -1062,7 +1054,7 @@ public static void editarDinheiroCliente() { String cliente = nome + "," + idTitular + "," + telefone + "," + email + "," + nif + "," + saldoTxt + "\n"; adicionaTextoAoFicheiro(cliente, "clientes.txt"); - } + } // Taxas baseadas no EURO static double[] taxas = { @@ -1144,81 +1136,66 @@ public static void editarDinheiroCliente() { } public static void moeda() { - - Scanner sc = new Scanner(System.in); - - int opcao = 1; - - while (opcao != 0) { - - System.out.println("\n=== MOEDAS DISPONIVEIS === "+ " ⣀⣠⣤⣤⣤⣀⡀"); - System.out.println("1 - EUR — € — European Union "+ " ⣀⣴⣿⣿⠿⠿⠿⠿⢿⣿⣷⠄"); - System.out.println("2 - USD — $ — United States "+ " ⢀⣴⣿⠟⠉⠀⠀⠀⠀⠀⠀⠈⠉⠀"); - System.out.println("3 - JPY — ¥ — Japan "+ " ⣀⣀⣀⣾⣿⣇⣀⣀⣀⣀⣀⣀⣀⣀⠀"); - System.out.println("4 - GBP — £ — United Kingdom "+ " ⠛⠛⢻⣿⣿⠛⠛⠛⠛⠛⠛⠛⠛⠛⠀"); - System.out.println("5 - CNY — ¥ — China "+ " ⣤⣤⣼⣿⣿⣤⣤⣤⣤⣤⣤⣤⣤⣤⠀"); - System.out.println("6 - AUD — A$ — Australia "+ " ⠉⠉⠉⢿⣿⣏⠉⠉⠉⠉⠉⠉⠉⠉⠀"); - System.out.println("7 - CAD — C$ — Canada "+ " ⠈⢻⣿⣦⣀⠀⠀⠀⠀⠀⠀⢀⣀⠀"); - System.out.println("8 - CHF — Fr — Switzerland "+ " ⠉⠻⣿⣿⣶⣶⣶⣶⣿⣿⡿⠃⠀\n" - + " ⠉⠙⠛⠛⠛⠉⠁⠀⠀⠀" ); - - int origem; - while (true) { - System.out.print("\nEscolha a moeda a converter: "); - origem = sc.nextInt(); - if (origem >= 1 && origem <= 8) break; - - System.out.println("Opção invalida. Insira novamente."); - - } - - int destino; - - while (true) { - - System.out.print("Escolhe a moeda pretendida: "); - - destino = sc.nextInt(); - - if (destino >= 1 && destino <= 8) break; - - System.out.println("Opção invalida. Insira novamente."); - - } - - System.out.print("Valor a converter: "); - - double valor = sc.nextDouble(); - - double resultado = converter(valor, origem - 1, destino - 1); - - System.out.println("\n=== RESULTADO ==="); - - System.out.println(valor + " " + - - simboloMoeda(origem) + - - " = " + - - resultado + - - " " + - - simboloMoeda(destino)); - - System.out.println("\n1 - Nova conversão"); - - System.out.println("0 - Sair"); - - System.out.print("Opção: "); - - opcao = sc.nextInt(); - - } - - System.out.println("Programa terminado."); - - } + Scanner sc = new Scanner(System.in); + int opcao; + + do { + System.out.println("\n=== MOEDAS DISPONIVEIS === " + " ⣀⣠⣤⣤⣤⣀⡀"); + System.out.println("1 - EUR — € — European Union " + " ⣀⣴⣿⣿⠿⠿⠿⠿⢿⣿⣷⠄"); + System.out.println("2 - USD — $ — United States " + " ⢀⣴⣿⠟⠉⠀⠀⠀⠀⠀⠀⠈⠉⠀"); + System.out.println("3 - JPY — ¥ — Japan " + " ⣀⣀⣀⣾⣿⣇⣀⣀⣀⣀⣀⣀⣀⣀⠀"); + System.out.println("4 - GBP — £ — United Kingdom " + " ⠛⠛⢻⣿⣿⠛⠛⠛⠛⠛⠛⠛⠛⠛⠀"); + System.out.println("5 - CNY — ¥ — China " + " ⣤⣤⣼⣿⣿⣤⣤⣤⣤⣤⣤⣤⣤⣤⠀"); + System.out.println("6 — AUD — A$ — Australia " + " ⠉⠉⠉⢿⣿⣏⠉⠉⠉⠉⠉⠉⠉⠉⠀"); + System.out.println("7 — CAD — C$ — Canada " + " ⠈⢻⣿⣦⣀⠀⠀⠀⠀⠀⠀⢀⣀⠀"); + System.out.println("8 — CHF — Fr — Switzerland " + " ⠉⠻⣿⣿⣶⣶⣶⣶⣿⣿⡿⠃⠀\n" + + " ⠉⠙⠛⠛⠛⠉⠁⠀⠀⠀"); + + int origem = 0; + while (true) { + System.out.print("\nEscolha a moeda a converter: "); + origem = sc.nextInt(); + if (origem >= 1 && origem <= 8) break; + System.out.println("Opção inválida. Insira novamente."); + } + + int destino = 0; + while (true) { + System.out.print("Escolha a moeda pretendida: "); + destino = sc.nextInt(); + if (destino >= 1 && destino <= 8) break; + System.out.println("Opção inválida. Insira novamente."); + } + + System.out.print("Valor a converter: "); + double valor = sc.nextDouble(); + + double resultado = converter(valor, origem - 1, destino - 1); + + System.out.println("\n=== RESULTADO ==="); + System.out.println(valor + " " + simboloMoeda(origem) + + " = " + resultado + " " + simboloMoeda(destino)); + + System.out.println("\n1 - Nova conversão"); + System.out.println("2 - Sair"); + System.out.print("Opção: "); + opcao = sc.nextInt(); + + switch(opcao) { + case 1: //Repetir + break; + case 2: + System.out.println("A sair da conversão de moedas..."); + break; + default: + System.out.println("Opção inválida! A encerrar..."); + opcao = 2; + } + + } while (opcao != 2); + + System.out.println("Programa terminado."); +} private static final String[] UNIDADES = { "zero", "um", "dois", "três", "quatro", "cinco", "seis", "sete", "oito", "nove" @@ -1286,7 +1263,7 @@ public static void editarDinheiroCliente() { System.out.println("│ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅̅ ̅ ̅ ̅ ̅ ̅ ̅ │"); System.out.println("│ │"); System.out.println("│ Pague por este cheque a: │"); - System.out.printf( "│ %-60s │%n", beneficiario); + System.out.printf( "│ %-59s │%n", beneficiario); System.out.println("│ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅̅ ̅ ̅ ̅ │"); System.out.println("│ │"); System.out.printf( "│ A quantia de: %-45s │%n", quantiaPorExtenso); @@ -1297,7 +1274,7 @@ public static void editarDinheiroCliente() { System.out.println("│ │"); System.out.printf( "│ %45s │%n", assinatura); System.out.println("│ ̅ ̅̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ │"); - System.out.printf( "│ %46s │%n", "Assinatura"); + System.out.printf( "│ %45s │%n", "Assinatura "); System.out.println( "│ │"); System.out.println("└──────────────────────────────────────────────────────────────┘"); diff --git a/target/classes/com/mycompany/mavenproject25/Mavenproject25.class b/target/classes/com/mycompany/mavenproject25/Mavenproject25.class index ef8aa33..7d99d71 100644 Binary files a/target/classes/com/mycompany/mavenproject25/Mavenproject25.class and b/target/classes/com/mycompany/mavenproject25/Mavenproject25.class differ