mardi 28 février 2017

problems with ArrayList in if-statement and for-loop

I have a question regardig the for-loop and ArrayList. I have a HashMap with String and Integers, where the String represents a class, and the Integer represents the grade. They I have a collection of students in an ArrayList. So what I am trying to do is find the average of the grades of the students in the ArrayList. This is the code of that class:

import java.util.ArrayList;

public class Bachelorstudenter {

private ArrayList<Bachelorstudent> bs;

public Bachelorstudenter() {

    bs = new ArrayList<>();
}

public int bsGjennomsnitt() {

    int sum = 0;
    int gjennomsnitt = 0;
  if(!bs.isEmpty()){
        for(Bachelorstudent b : bs.values){
            sum += b.finnGjennomsnitt();
        }
    return gjennomsnitt;
  }else {

    return 6;
  }
} 
}

I know that the bs.values in the for-loop within the if-statement is wrong, but I've tried googleing what I should use instead, and neither .contains or .size works.

Oh, and I also have another class called Bachelorstudent, where I can create an object of the Bachelorstudent and it will be put in the ArrayList in Bachelorstudenter.

Does anyone know what I need to put there instead?

Aucun commentaire:

Enregistrer un commentaire