Compare commits

..

5 Commits

Author SHA1 Message Date
250413
6c663f4381 concertos 2026-05-18 11:46:20 +01:00
ba14a7dfd5 Leve mudança no visual 2026-05-11 14:38:26 +00:00
250413
d6f33fc89c fazendo os sistemas de clientes e do admin(Ajustes) 2026-05-11 12:46:05 +01:00
250413
22c44238c1 fazendo os sistemas de clientes e do admin 2026-05-11 12:02:40 +01:00
250413
59ff5e00c5 fazendo os sistemas de clientes e do admin 2026-05-11 11:53:31 +01:00
2 changed files with 99 additions and 52 deletions

View File

@@ -1 +1 @@
çjhef,8973425,312430868,2784935,pouywrepguyepiher.com,90.0. Tiago Silva,195572,913538232,250422@epvc.pt,228389992,500.0

View File

@@ -30,7 +30,7 @@ public class Mavenproject25 {
System.out.println("══════════════════════════════════════\n" + System.out.println("══════════════════════════════════════\n" +
" Seleciona uma das opções\n" + " Seleciona uma das opções\n" +
"══════════════════════════════════════\n" + "══════════════════════════════════════\n" +
" [1] Contas clientes\n" + " [1] Criar conta\n" +
" [2] Login\n" + " [2] Login\n" +
" [3] Sair\n" + " [3] Sair\n" +
"══════════════════════════════════════" "══════════════════════════════════════"
@@ -38,11 +38,13 @@ public class Mavenproject25 {
+ "\n"); + "\n");
int opcao = scanner.nextInt(); int opcao = scanner.nextInt();
switch (opcao) { switch (opcao) {
case 1 -> acessoContaCliente(); case 1 -> adicionarNovoCliente();
// case 2 -> case 2 -> acessoContaCliente();
case 3 -> desligar = true; case 3 -> desligar = true;
case 2026 -> areaAdmin();
default -> default ->
System.out.println("Opção inválida"); System.out.println("Opção inválida");
} }
@@ -251,20 +253,21 @@ private static void menuClienteLogado(String[] dadosCliente) {
Scanner scanner = new Scanner(System.in); Scanner scanner = new Scanner(System.in);
boolean sair = false; boolean sair = false;
double saldo = Double.parseDouble(dadosCliente[5]); double saldo = Double.parseDouble(dadosCliente[4]);
while (!sair) { while (!sair) {
System.out.printf("\n" System.out.printf("\n"
+ "╔════════════════════════════════════════╗\n" + "╔════════════════════════════════════════╗\n"
+ "║ BEM-VINDO, %-15s\n" + " BEM-VINDO \n"
+ "╠════════════════════════════════════════╣\n" + "╠════════════════════════════════════════╣\n"
+ " SEU SALDO: €%.2f\n" + "SEU SALDO: "+ saldo +" \n"
+ "╠════════════════════════════════════════╣\n" + "╠════════════════════════════════════════╣\n"
+ "║ ▸ 1 Consultar meus dados ║\n" + "║ ▸ 1 Consultar meus dados ║\n"
+ "║ ▸ 2 Transferir dinheiro ║\n" + "║ ▸ 2 Transferir dinheiro ║\n"
+ "║ ▸ 3 Depositar dinheiro ║\n" + "║ ▸ 3 Depositar dinheiro ║\n"
+ "║ ▸ 4 Levantar dinheiro ║\n" + "║ ▸ 4 Levantar dinheiro ║\n"
+ "║ ▸ 5 Sair \n" + "║ ▸ 5 Cheque\n"
+ "║ ▸ 6 Sair ║\n"
+ "╚════════════════════════════════════════╝\n", + "╚════════════════════════════════════════╝\n",
dadosCliente[0], saldo); dadosCliente[0], saldo);
@@ -286,7 +289,8 @@ private static void menuClienteLogado(String[] dadosCliente) {
saldo = levantarDinheiro(saldo); saldo = levantarDinheiro(saldo);
atualizarSaldoCliente(dadosCliente[1], saldo); atualizarSaldoCliente(dadosCliente[1], saldo);
break; break;
case 5: case 5 : cheque();
case 6:
sair = true; sair = true;
System.out.println("A sair da conta..."); System.out.println("A sair da conta...");
break; break;
@@ -299,12 +303,12 @@ private static void menuClienteLogado(String[] dadosCliente) {
System.out.println("\n╔════════════════════════════════════════╗"); System.out.println("\n╔════════════════════════════════════════╗");
System.out.println("║ SEUS DADOS PESSOAIS ║"); System.out.println("║ SEUS DADOS PESSOAIS ║");
System.out.println("╠════════════════════════════════════════╣"); System.out.println("╠════════════════════════════════════════╣");
System.out.printf("║ Nome: %-25s\n", dados[0]); System.out.printf("║ Nome: \n", dados[0]);
System.out.printf("║ ID: %-25s\n", dados[1]); System.out.printf("║ ID: \n", dados[1]);
System.out.printf("║ Telefone: %-25s\n", dados[2]); System.out.printf("║ Telefone: \n", dados[2]);
System.out.printf("║ Email: %-25s\n", dados[3]); System.out.printf("║ Email: \n", dados[3]);
System.out.printf("║ NIF: %-25s\n", dados[4]); System.out.printf("║ NIF: \n", dados[4]);
System.out.printf("║ Saldo: €%-24s\n", dados[5]); System.out.printf("║ Saldo: \n", dados[5]);
System.out.println("╚════════════════════════════════════════╝\n"); System.out.println("╚════════════════════════════════════════╝\n");
} }
@@ -537,7 +541,7 @@ private static void procurarClienteAdmin() {
} }
if (!encontrado) { if (!encontrado) {
System.out.println("Cliente não encontrado."); System.out.println("Cliente não encontrado.");
} }
} }
@@ -550,7 +554,7 @@ private static void editarClienteAdmin() {
String[] dadosCliente = procurarClientePorId(id); String[] dadosCliente = procurarClientePorId(id);
if (dadosCliente == null) { if (dadosCliente == null) {
System.out.println("Cliente não encontrado!"); System.out.println("Cliente não encontrado!");
return; return;
} }
@@ -567,10 +571,10 @@ private static void editarClienteAdmin() {
if (!telefoneJaExiste(novoTelefone) || dadosCliente[2].equals(novoTelefone)) { if (!telefoneJaExiste(novoTelefone) || dadosCliente[2].equals(novoTelefone)) {
dadosCliente[2] = novoTelefone; dadosCliente[2] = novoTelefone;
} else { } else {
System.out.println("Telefone já existe! Mantido o original."); System.out.println("Telefone já existe! Mantido o original.");
} }
} else { } else {
System.out.println("Telefone inválido! Mantido o original."); System.out.println("Telefone inválido! Mantido o original.");
} }
} }
@@ -579,11 +583,11 @@ private static void editarClienteAdmin() {
if (!novoEmail.isEmpty() && verificarEmail(novoEmail)) { if (!novoEmail.isEmpty() && verificarEmail(novoEmail)) {
dadosCliente[3] = novoEmail; dadosCliente[3] = novoEmail;
} else if (!novoEmail.isEmpty()) { } else if (!novoEmail.isEmpty()) {
System.out.println("Email inválido! Mantido o original."); System.out.println("Email inválido! Mantido o original.");
} }
atualizarClienteCompleto(dadosCliente); atualizarClienteCompleto(dadosCliente);
System.out.println("Cliente atualizado com sucesso!"); System.out.println("1Cliente atualizado com sucesso!");
} }
private static void removerCliente() { private static void removerCliente() {
@@ -684,14 +688,14 @@ private static void mostrarEstatisticas() {
double saldoMedio = saldoTotal / numClientes; double saldoMedio = saldoTotal / numClientes;
System.out.println("\n╔════════════════════════════════════════════════════════════════╗"); System.out.println("\n╔════════════════════════════════════════════════════════════════╗");
System.out.println("║ ESTATÍSTICAS DO SISTEMA ║"); System.out.println( "║ ESTATÍSTICAS DO SISTEMA ║");
System.out.println("╠════════════════════════════════════════════════════════════════╣"); System.out.println( "╠════════════════════════════════════════════════════════════════╣");
System.out.printf("║ %-58s \n", "Total de clientes: " + numClientes); System.out.printf( "\n", "Total de clientes: " + numClientes);
System.out.printf("║ %-58s \n", String.format("Saldo total do banco: €%.2f", saldoTotal)); System.out.printf( "\n", String.format("Saldo total do banco: ", saldoTotal));
System.out.printf("║ %-58s \n", String.format("Saldo médio por cliente: €%.2f", saldoMedio)); System.out.printf( "\n", String.format("Saldo médio por cliente: ", saldoMedio));
System.out.printf("║ %-58s \n", String.format("Cliente com maior saldo: %s (€%.2f)", clienteSaldoMaximo, saldoMaximo)); System.out.printf( "\n", String.format("Cliente com maior saldo: ", clienteSaldoMaximo, saldoMaximo));
System.out.printf("║ %-58s \n", String.format("Cliente com menor saldo: %s (€%.2f)", clienteSaldoMinimo, saldoMinimo)); System.out.printf( "\n", String.format("Cliente com menor saldo: ", clienteSaldoMinimo, saldoMinimo));
System.out.println("╚════════════════════════════════════════════════════════════════╝\n"); System.out.println( "╚════════════════════════════════════════════════════════════════╝\n");
} }
private static void atualizarClienteCompleto(String[] dados) { private static void atualizarClienteCompleto(String[] dados) {
@@ -734,7 +738,7 @@ private static void atualizarClienteCompleto(String[] dados) {
return false; return false;
} }
// Separar os dígitos
int d1 = Character.getNumericValue(nif.charAt(0)); int d1 = Character.getNumericValue(nif.charAt(0));
int d2 = Character.getNumericValue(nif.charAt(1)); int d2 = Character.getNumericValue(nif.charAt(1));
int d3 = Character.getNumericValue(nif.charAt(2)); int d3 = Character.getNumericValue(nif.charAt(2));
@@ -745,7 +749,7 @@ private static void atualizarClienteCompleto(String[] dados) {
int d8 = Character.getNumericValue(nif.charAt(7)); int d8 = Character.getNumericValue(nif.charAt(7));
int d9 = Character.getNumericValue(nif.charAt(8)); int d9 = Character.getNumericValue(nif.charAt(8));
// Cálculo do dígito de controlo
int produto = (d8 * 2) + (d7 * 3) + (d6 * 4) + (d5 * 5) + int produto = (d8 * 2) + (d7 * 3) + (d6 * 4) + (d5 * 5) +
(d4 * 6) + (d3 * 7) + (d2 * 8) + (d1 * 9); (d4 * 6) + (d3 * 7) + (d2 * 8) + (d1 * 9);
int resto = produto % 11; int resto = produto % 11;
@@ -757,7 +761,7 @@ private static void atualizarClienteCompleto(String[] dados) {
digitoControlo = 11 - resto; digitoControlo = 11 - resto;
} }
// Verificar se o dígito de controlo está correto
if (digitoControlo == d9) { if (digitoControlo == d9) {
return true; return true;
} else { } else {
@@ -864,7 +868,7 @@ public static void editarDinheiroCliente() {
String novoNIF = scanner.nextLine(); String novoNIF = scanner.nextLine();
if (!novoNIF.isEmpty()) nif[indiceEditar] = novoNIF; if (!novoNIF.isEmpty()) nif[indiceEditar] = novoNIF;
// Reescrever o ficheiro com os dados atualizados
StringBuilder conteudoAtualizado = new StringBuilder(); StringBuilder conteudoAtualizado = new StringBuilder();
for (int i = 0; i < nome.length; i++) { for (int i = 0; i < nome.length; i++) {
conteudoAtualizado.append(nome[i]).append(",") conteudoAtualizado.append(nome[i]).append(",")
@@ -897,9 +901,7 @@ public static void editarDinheiroCliente() {
private static String gerarID() { private static String gerarID() {
boolean idFeito = true; boolean idFeito = true;
while(true){ while(true){
String CARACTERES = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + String CARACTERES = "0123456789";
"abcdefghijklmnopqrstuvwxyz" +
"0123456789";
SecureRandom random = new SecureRandom(); SecureRandom random = new SecureRandom();
StringBuilder idNum = new StringBuilder(6); StringBuilder idNum = new StringBuilder(6);
@@ -908,33 +910,33 @@ public static void editarDinheiroCliente() {
int indice = random.nextInt(CARACTERES.length()); int indice = random.nextInt(CARACTERES.length());
idNum.append(CARACTERES.charAt(indice)); idNum.append(CARACTERES.charAt(indice));
} }
// ver se id já existe
String idTxt = idNum.toString(); String idTxt = idNum.toString();
if(!idJaExiste(idTxt)){ if(!idJaExiste(idTxt)){
return idTxt; return idTxt;
// } }
} }
} }
private static boolean nifJaExiste(String nif) { private static boolean nifJaExiste (String nif) {
String nomeFicheiro = "clientes.txt"; String nomeFicheiro = "clientes.txt";
// 1. Começamos assumindo que NÃO existe
try (BufferedReader reader = new BufferedReader(new FileReader(nomeFicheiro))) { try (BufferedReader reader = new BufferedReader(new FileReader(nomeFicheiro))) {
String linha; String linha;
while ((linha = reader.readLine()) != null) { while ((linha = reader.readLine()) != null) {
String[] campos = linha.split(","); String[] campos = linha.split(",");
// 2. Verificamos se a linha tem dados e se o NIF coincide
if (campos.length > 0 && campos[0].trim().equals(nif.trim())) { if (campos.length > 0 && campos[0].trim().equals(nif.trim())) {
return true; // Encontrou? Retorna imediatamente e fecha o reader return true;
} }
} }
} catch (IOException e) { } catch (IOException e) {
// Opcional: imprimir erro para saber por que a leitura falhou
System.err.println("Erro ao ler o ficheiro: " + e.getMessage()); System.err.println("Erro ao ler o ficheiro: " + e.getMessage());
} }
return false; // Se percorreu tudo e não achou, retorna false return false;
} }
@@ -1020,7 +1022,7 @@ private static boolean nifJaExiste(String nif) {
} while (!verificarNIF(nif) || nif.isEmpty()); } while (!verificarNIF(nif) || nif.isEmpty());
String telefone; String telefone;
do {
System.out.print("║ Introduza telefone (9 dígitos): "); System.out.print("║ Introduza telefone (9 dígitos): ");
telefone = scanner.nextLine(); telefone = scanner.nextLine();
@@ -1031,20 +1033,20 @@ private static boolean nifJaExiste(String nif) {
System.out.println("║ Por favor, insira um telefone diferente."); System.out.println("║ Por favor, insira um telefone diferente.");
telefone = ""; telefone = "";
} }
} while (telefone.isEmpty() || telefone.length() != 9 || !telefone.matches("\\d+")); while (telefone.isEmpty() || telefone.length() != 9 || !telefone.matches("\\d+"));
String email; String email;
do {
System.out.print("║ Introduza email: "); System.out.print("║ Introduza email: ");
email = scanner.nextLine(); email = scanner.nextLine();
if (!verificarEmail(email)) { if (!verificarEmail(email)) {
System.out.println("║ Email inválido! Deve conter @ e .pt ou .com"); System.out.println("║ Email inválido! Deve conter @ e .pt ou .com");
} }
} while (!verificarEmail(email)); while (!verificarEmail(email));
double saldo; double saldo;
do {
System.out.print("║ Introduza saldo (mínimo 60€): "); System.out.print("║ Introduza saldo (mínimo 60€): ");
saldo = scanner.nextDouble(); saldo = scanner.nextDouble();
scanner.nextLine(); // limpar buffer scanner.nextLine(); // limpar buffer
@@ -1052,7 +1054,7 @@ private static boolean nifJaExiste(String nif) {
if (saldo < 60) { if (saldo < 60) {
System.out.println("║ Saldo mínimo insuficiente! Mínimo 60€."); System.out.println("║ Saldo mínimo insuficiente! Mínimo 60€.");
} }
} while (saldo < 60); while (saldo < 60);
String saldoTxt = Double.toString(saldo); String saldoTxt = Double.toString(saldo);
@@ -1219,5 +1221,50 @@ private static boolean nifJaExiste(String nif) {
System.out.println("Programa terminado."); System.out.println("Programa terminado.");
} }
public static void cheque(){
Scanner scanner = new Scanner(System.in);
System.out.print("Nome do beneficiário: ");
String beneficiario = scanner.nextLine();
System.out.print("Localidade: ");
String localidade = scanner.nextLine();
System.out.print("Data (dd/mm/aaaa): ");
String data = scanner.nextLine();
System.out.print("Quantia do valor por extenso: ");
String quantia = scanner.nextLine();
System.out.print("Valor do cheque: ");
double valor = scanner.nextDouble();
scanner.nextLine();
System.out.print("Assinatura: ");
String assinatura = scanner.nextLine();
System.out.println("┌──────────────────────────────────────────────────────────────┐\n" +
"│ CHEQUE │\n" +
"│ │\n" +
"│ Banco: Banco Horizonte │\n" +
"│ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ │\n" +
"│ Localidade: "+ localidade +" Data: "+ data +"\n" +
"│ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅̅ ̅ ̅ ̅ ̅ ̅ ̅ │\n" +
"│ Pague por este cheque a: │\n" +
""+ beneficiario +"\n" +
"│ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅̅ ̅ ̅ ̅ │\n" +
"│ A quantia de: "+quantia+"\n" +
"│ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅̅ ̅ ̅ │\n" +
"│ │\n" +
"│ Valor: "+ valor +"€ │\n" +
"│ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ │\n" +
"│ │\n" +
""+assinatura+"\n" +
"│ ̅ ̅̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ │\n" +
"│ Assinatura │\n" +
"│ │\n" +
"└──────────────────────────────────────────────────────────────┘");
} }
}