-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBanco.java
More file actions
74 lines (53 loc) · 2.33 KB
/
Banco.java
File metadata and controls
74 lines (53 loc) · 2.33 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import java.util.Scanner;
public class Bank {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Name: ");
String name = scanner.next();
System.out.println("Account type: ");
String accountType = scanner.next();
System.out.println("Initial balance: ");
double initialBalance = scanner.nextDouble();
System.out.println(String.format("""
***********************************
Client initial data:
Name: %s
Account type: %s
Initial balance: $ %.2f
***********************************
""", name, accountType, initialBalance));
while (true) {
System.out.println("""
Operations:
1 - Check balance
2 - Receive money
3 - Transfer money
4 - Exit
""");
int option = scanner.nextInt();
if (option == 1) {
System.out.println(String.format("Your current balance is: %.2f", initialBalance));
} else if (option == 2) {
System.out.println("Enter the amount to receive: ");
double amountReceived = scanner.nextDouble();
initialBalance += amountReceived;
System.out.println(String.format("Updated balance: %.2f", initialBalance));
} else if (option == 3) {
System.out.println("Enter the amount to transfer: ");
double amountToTransfer = scanner.nextDouble();
if (amountToTransfer > initialBalance) {
System.out.println("Invalid option: insufficient balance.");
} else {
initialBalance -= amountToTransfer;
System.out.println(String.format("Updated balance: %.2f", initialBalance));
}
} else if (option == 4) {
System.out.println("GOODBYE!");
break;
} else {
System.out.println("Invalid option, please enter a valid one.");
}
}
scanner.close();
}
}