Created
April 23, 2025 02:51
-
-
Save ederfsantos/0425976a4b55d8608b53fdc89d4ce837 to your computer and use it in GitHub Desktop.
Desafio da conta bancaria Alura One
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Desafio { | |
public static void main(String[] args) { | |
String nomeDoCliente; | |
String tipoDeConta; | |
String dadosCliente; | |
double saldoInicial = 0; | |
double deposito = 0; | |
double transferencia = 0; | |
int opcao; | |
System.out.println("Sistema de movimentação de operações bancárias"); | |
System.out.println("**********************************************"); | |
Scanner ler = new Scanner(System.in); | |
System.out.println("Informe o nome do cliente:"); | |
nomeDoCliente = ler.nextLine(); | |
System.out.println("Informe o tipo de conta(Corrente,Poupança):"); | |
tipoDeConta = ler.nextLine(); | |
System.out.println("Informe o valor do saldo inicial:"); | |
saldoInicial = ler.nextDouble(); | |
System.out.println("**********************************************"); | |
dadosCliente = """ | |
Nome do cliente: %s | |
Tipo de conta: %s | |
Saldo inicial R$ = %.2f | |
""".formatted(nomeDoCliente, tipoDeConta, saldoInicial); | |
System.out.println("Dados iniciais do cliente\n" + dadosCliente); | |
System.out.println("**********************************************"); | |
do { | |
System.out.println("Menu de operações"); | |
System.out.println("1- Consultar saldos\n2- Receber valor\n3- Transferir valor\n4- Sair\nDigite a opção desejada:"); | |
opcao = ler.nextInt(); | |
switch (opcao) { | |
case 1: { | |
System.out.println("O saldo disponível é de R$ " + String.format("%.2f", saldoInicial)); | |
break; | |
} | |
case 2: { | |
System.out.println("Informe o valor a receber:"); | |
deposito = ler.nextDouble(); | |
saldoInicial += deposito; | |
System.out.println("O saldo disponível na conta é de R$ " + String.format("%.2f", saldoInicial)); | |
break; | |
} | |
case 3: { | |
System.out.println("Informe o valor a transferir:"); | |
transferencia = ler.nextDouble(); | |
if (transferencia <= saldoInicial) { | |
saldoInicial -= transferencia; | |
System.out.println("Transferência realizada com sucesso!\n Seu novo saldo em conta é R$ " + String.format("%.2f", saldoInicial)); | |
} else { | |
System.out.println("Não foi possivel realizar a tranferência, saldo insuficiente!"); | |
} | |
break; | |
} | |
case 4: { | |
System.out.println("Saindo do programa!Até a próxima!"); | |
break; | |
} | |
default: { | |
System.out.println("Opção inválida!"); | |
} | |
} | |
} while (opcao != 4); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment