Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

Meu exemplo de conta corrente - switch - case com inclusao das variáveis do Cliente.

import java.util.Scanner;

public class ContaCorrente {
    public static void main(String[] args) {
        String name = "";
        String typeAccount = ""; //Current
        double balance = 0;
        int options = 0;
        double newValue;
        double amountTransfer = 0;
        Scanner reading = new Scanner(System.in);

        System.out.print("Insert the Client name: ");
        name = reading.nextLine();
        System.out.print("Define the type account: ");
        typeAccount = reading.nextLine();
        System.out.print("Insert the initial balance account: ");
        balance = reading.nextDouble();
        System.out.print("\n");

        System.out.println("***************************");
        System.out.println("Data Client : ");

        System.out.println("Name: " + name);
        System.out.println("Account Type: " + typeAccount);
        System.out.println("Initial Balance: " + balance);
        System.out.println("***************************\n");

        String menu = """
                \nMenu Options
                1- Check the Balance
                2- Transfer Amount
                3- Enter the Amount
                4- Exit
                \nChoose the options:""";

        //Scanner reading = new Scanner(System.in);
        while (options != 4) {
            System.out.print(menu);
            options = reading.nextInt();
            switch (options){
                case 1:
                    balance = balance;
                    System.out.println("The balance is " + balance);
                    break;

                case 2:
                    System.out.print("Insert the value to transfer: ");
                    amountTransfer = reading.nextDouble();
                    if (amountTransfer <= 0){
                        System.out.println("You can not to transfer the value less than zero or than Zero.");
                        balance = balance;//amountTransfer;
                        System.out.printf("Your balance is $%.2f. Insert the limite value or less.", balance);
                        System.out.print("\nInsert the transfer value to transfer: ");
                        amountTransfer = reading.nextDouble();
                        balance -= amountTransfer;
                        System.out.println("The balance is " + balance);

                    }else if (amountTransfer > balance){
                        System.out.println("Isn't possible to transfer, You haven't money.");
                        System.out.printf("Your balance is $%.2f. Insert the limite value or less.", balance);
                        System.out.print("\nInsert the transfer value to transfer: ");
                        amountTransfer = reading.nextDouble();
                        balance -= amountTransfer;
                        System.out.println("The balance is " + balance);
                    }else if(amountTransfer <= balance) {
                        balance -= amountTransfer;
                        System.out.println("The balance is " + balance);
                    }
                    break;

                case 3:
                    if (options == 3) {
                        System.out.print("Insert the value to account: ");
                        newValue = reading.nextDouble();
                        if (newValue <= 0){
                            System.out.println("You need to insert the value more than Zero.");
                            newValue = 0;
                        }else {
                            //System.out.println("You need to insert the value more than Zero.");
                            balance += newValue;
                            System.out.println("The balance is " + balance);
                        }
                    }
                    break;

                case 4:
                    System.out.println("Exit the transactions Account.\n") ;

                    System.out.println("***************************");
                    System.out.println("New Data Client : ") ;

                    System.out.println("Name : " + name) ;
                    System.out.println("Account Type : " + typeAccount) ;
                    System.out.println("Initial Balance : " + balance) ;
                    System.out.println("***************************\n");

                    break;

                default:
                    System.out.println("Select the number option from the menu (1, 2, 3, or 4)") ;
                    break;
            }
        }
    }
}

1 resposta
solução!

Olá, Marcelo! Tudo bem?

Você fez um ótimo trabalho resolvendo o desafio! Seu código está correto, então te parabenizo pelo seu esforço e dedicação!

A título de informação, quando precisar compartilhar códigos aqui no fórum é interessante dar uma boa visibilidade para ele. Para isso, você pode seguir os passos que compartilho a seguir. Sem a formatação correta, o código acaba ficando escondido e de difícil visualização.

OBS: no seu caso, algumas partes do código ficaram formatadas devido à endentação do código, mas atrapalha um pouco na visualização do código.

  1. Selecione o trecho com o código no seu post;

  2. Aqui no fórum, procure o ícone </>. É a sétima opção na aba superior do nosso editor de texto;

  3. Clique no ícone comentado acima, certificando-se que está com todo o trecho de código selecionado.

Para confirmar se está tudo certo, você pode pré-visualizar seu post clicando no penúltimo ícone da esquerda para a direita, ou também usando o atalho F9.

No mais, se precisar de ajuda ou tiver alguma dúvida relacionada aos seus estudos, o fórum é o melhor lugar para te ajudar.

Bons estudos!