-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimulacaoBancaria.java
More file actions
50 lines (39 loc) · 1.7 KB
/
SimulacaoBancaria.java
File metadata and controls
50 lines (39 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import java.util.Scanner;
public class SimulacaoBancaria {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double saldo = 0;
// Loop infinito para manter o programa em execução até que o usuário decida sair
while (true) {
int opcao = scanner.nextInt();
// TODO: Implemente as condições necessárias para avaliaa a opção escolhida:
// Dica: Utilze o switch/case para o programa realizar as operações escolhidas pelo usuário.
switch(opcao){
case 1 :
double valorDepositado = scanner.nextDouble();
saldo += valorDepositado;
System.out.println(" Saldo atual: " + valorDepositado);
break;
case 2 :
double valorSaque = scanner.nextDouble();
if (valorSaque <= saldo){
saldo -= valorSaque;
System.out.println("Saldo atual: " + valorSaque);
}else{
System.out.println("Saldo insuficiente.");
}
break;
case 3 :
System.out.println("Saldo atual: " + saldo);
break;
case 0 :
System.out.println("Programa encerrado.");
System.exit(0);
break;
// Exibe mensagem de opção inválida se o usuário escolher uma opção inválida:
default:
System.out.println("Opção inválida. Tente novamente.");
}
}
}
}