Hola a todos, les comparto mi versión de la cuenta bancaria en caso de que a alguno les sirva :)
import java.util.Random; import java.util.Scanner;
public class Bank { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int option = 0; double balance = new Random().nextDouble() * 10000;
System.out.println("Welcome to the bank!");
System.out.println("Please enter your name: ");
String name = scanner.nextLine();
System.out.println("Please enter the account type: ");
String accountType = scanner.nextLine();
String information = """
Name: %s
Account type: %s
Balance: %.2f
""".formatted(name, accountType, balance);
String menu = """
** Write the number of the operation you want to do **
1. Consult
2. Withdraw
3. Deposit
9. Exit
""";
System.out.println(information);
while (option != 9){
System.out.println(menu);
option = scanner.nextInt();
switch (option){
case 1:
System.out.println("Your balance updated is: " + balance);
break;
case 2:
System.out.println("Enter the amount you want to withdraw: ");
double withdraw = scanner.nextDouble();
if (withdraw > balance){
System.out.println("You don't have enough balance");
} else {
balance -= withdraw;
System.out.println("Withdrawal successful");
}
break;
case 3:
System.out.println("Enter the amount you want to deposit: ");
double deposit = scanner.nextDouble();
balance += deposit;
System.out.println("Deposit successful");
break;
case 9:
System.out.println("Goodbye!");
break;
default:
System.out.println("Invalid option");
}
}
}
}