Problem calling class inside Switch

Asked

Viewed 914 times

1

I’m developing a facul project that’s a basic clinical system. After the user logs in, they choose an option in the menu where the responsible class will be called. The problem that when I choose any menu option it asks again the user login and does not call the class corresponding to function..

public void telaLogin(){
    int cont = 0;
    System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
    System.out.println("------- Bem Vindo ao Sis-Clinica ------");
    System.out.println("   - LOGIN - ");
    do{
        System.out.print("Login: ");
        usuario = ler.next();
        System.out.print("\nSenha: ");
        senha = ler.next();

        if(usuario.equals("admin")&& (senha.equals("12345"))){
            System.out.println("Acesso confirmado!");
            Inicio();
        }else{
            System.out.println("Acesso negado!"+'\n'+"---- Digite novamente ----"+'\n');
            cont++;
        if(cont == 3){
            System.out.println("Sitema bloqueando. "+'\n'+"Encerrando!!!");
            System.exit(0);
            }
        }
    }while(cont <= 3);       
}

public void Inicio(){
    int opcoes;
    System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
    System.out.println("------- Bem Vindo ao Sis-Clinica ------");
    System.out.println("   - INICIO - ");

    System.out.println(" 1 - NOVO ATENDIMENTO");
    System.out.println(" 2 - CONSULTAR PACIENTE");
    System.out.println(" 3 - EDITAR CADASTRO");
    System.out.println(" 4 - ENVIAR CONSULTA");
    System.out.println(" 5 - NOTIFICAR O PACIENTE");
    System.out.println(" 6 - SAIR");
    System.out.println("Escolha: ");
    opcoes = ler.nextInt();

    switch(opcoes){
        case 1:
            Cadastrar cad = new Cadastrar();
            break;
        case 2:
            Consultar cons = new Consultar();
            break;
        case 3:
            Editar edt = new Editar();
            break;
        case 4:
            Enviar env = new Enviar();
            break;
        case 5:
            Notificar not = new Notificar();
            break;
        case 6:
            System.out.println("Encerrando!!!");
            System.exit(0);
            break;
    }
}

Class

public class Cadastrar {

    Scanner ler = new Scanner(System.in);
    String nomeArq="Relatorio.pdf";
    String nome;
    String ender;
    String email;
    String tel;
    String bairro;
    String numero;
    String exame;

    public void Inserir(){
    File arquivo; 
    System.out.printf("Nome completo do paciente: ");
    nome = ler.nextLine();
    System.out.printf("Endereço: ");
    ender = ler.nextLine();
    System.out.printf("Bairro: ");
    bairro = ler.nextLine();
    System.out.printf("Número: ");
    numero = ler.nextLine();
    System.out.printf("Telefone: ");
    tel = ler.nextLine();
    System.out.printf("E-mail: ");
    email = ler.nextLine();
    System.out.printf("Exame: ");
    exame = ler.nextLine();

    nomeArq = nome +".txt";

    try
    {
      Formatter saida = new Formatter(nomeArq);
      saida.format("          --- Ficha cadastral de pacientes ---");
      saida.format("\n Nome do paciente: "+nome+"\n");
      saida.format("\n Endereço: "+ender+"\n");
      saida.format("\n Bairro: "+bairro+"\n");
      saida.format("\n Numero: "+numero+"\n");
      saida.format("\n Email: "+email+"\n");
      saida.format("\n Telefone: "+tel+"\n");
      saida.format("\n Exame: "+exame+"\n");
      saida.close();
        System.out.println("Arquivo '"+nomeArq+"' Salvo com sucesso!");
    }
    //mostrando erro em caso se nao for possivel gerar arquivo
    catch(Exception erro){
      System.out.println("Arquivo nao pode ser gerado!");
    }
    }
}
  • See your case is using the string or integer value. Check.

  • I updated you guys

1 answer

1


The problem is why you’re not stopping the while

if(usuario.equals("admin")&& (senha.equals("12345"))){
            System.out.println("Acesso confirmado!");
            Inicio();
            break;//impede que o while seja executado novamente
        }
  • In that case it’s coming out of the loop.. but it’s not calling the classes, because it soon stops running.

  • let me get this straight, after choosing option 1 to run? if this is the case you can call the Register method again Cad = new Register(); start(); break; or for all menu items vc would like to log in again?

  • No, as soon as you choose the option, you can change the corresponding screen (class). The problem now that when choosing the option it does not enter the class and stops running

  • please place the register class.

  • David taking advantage and I already ask how to open this file I am saving in this class, in another class, but in this other class he will open the file where the patient information is and just add the information related to the exam, and so save everything. Got it?

  • what is missing is you start the insert method to put Register Cad = new Register(); Cad.Insert();Start();break;

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.