Using another class Return

Asked

Viewed 50 times

1

Good morning friends, I’m trying to implement this code but it’s giving error.

 public int totalFaltasAluno(int matricula) {
        int totalFaltas = 0;
        for(Integer item : faltas){
            if(item == matricula){
                totalFaltas++;
            } 
        }
        return   totalFaltas;

 public boolean verificarReprovacaoPorFalta(int matricula) {
    int presenca = 90 - totalFaltas;//90 são os dias de aulas
    if (presenca  < (90-0.75-90));// presenca menor que 75% de 90 dias de aulas
         return true;
}

error:

    Exception in thread "main" java.lang.Error: Unresolved compilation 
    problem: 
    totalFaltas cannot be resolved to a variable

at Gerenciar_frequencia.Pauta.verificarReprovacaoPorFalta(Pauta.java:45)

Main class is like this.

 if (pauta.verificarReprovacaoPorFalta(aluno.getMatricula())){
            System.out.println(" Presença: reprovado");
        }
        else{
            System.out.println(" Presença: normal");
        }

1 answer

1


You need to call the method to make use of it. I leave below a commented example:

 public int totalFaltasAluno(int matricula) {
        int totalFaltas = 0;
        for(Integer item : faltas){
            if(item == matricula){
                totalFaltas++;
            } 
        }
        return   totalFaltas;
 }
 public boolean verificarReprovacaoPorFalta(int matricula) {
    // aplicando regra de 3 para saber o percentual dessa quantidade de faltas
    double percentualDePresenca = ((90 - totalFaltasAluno(matricula)) * 100) / 90;

    // comparando o percentual para ver se é menor que 75% de 90 dias.
    return (percentualDePresenca < 75);
 }

I don’t quite understand your logic for the method totalFaltasAluno but to solve the mentioned problem, just call the method instead of the variable because it does not exist in the definition of the class only locally in the method.

  • thanks for the reply, I added a part of the main class, I could not implement , the return is always stay "true".

  • to stay true always the presence is being less than (90-0.75-90) = -0.75..

  • I’ve edited the algorithm, so if you want 75% of 90 it’s only 90 by 0.75 and not subtract. To know how many % the amount X of fouls represents in 90 it is necessary to make use of the rule of 3. I edited the algorithm.

  • Hiago Souza, is returning true always, but thank you.

  • What value has in totalFaltas?

  • Now that I noticed the name of the method I updated the routines..

  • I have 3 total fouls , are 27, 6, 0

  • Try again, I edited the script... I got confused here

  • thanks again Hiago, but is returning true again.

Show 5 more comments

Browser other questions tagged

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