# Thread: How to count the number of an element using an argument?

1. Member
Join Date
Nov 2015
Posts
17
Rep Power
0

## How to count the number of an element using an argument?

Good afternoon!

I'm learning how to run collection and Exception at my university.

I have a code I have to fill in in order to count the number of vehicules using a fuel gived as an argument:

Here is the code:

Java Code:
```import java.util.*;

class Vehicule{
int no;
int puissance;
String fuel;
static List LV = new LinkedList();
Moteur motorisation;
static int = 10;
Vehicule (String carb, int p){
no=NoC++;
if(carb=="Diesel"){
fuel= carb;
puissance = p;
this.motorisation = new Diesel();
motorisation = motorisation.this;
}
if(carb == "Essence"){
fuel= carb;
puissance = p;
this.motorisation = new Essence();
motorisation = motorisation.this;
}
}
}

static int NbModeles(String carburant){
int n = 0;

FILL IN

}

class Moteur implements Comparable{
String carburant;
int no;
int puissance;
static set ListeMoteurs = new TreeSet();
static String MotorisationDefaut(Vehicule v){
return "Diesel";
}
Set puissancesDispo(Moteur m)
{
Set s = new TreeSet(); return s;
}
}```
I tried:

Java Code:
```static int NbModeles(String fuel){
int n = 0;

retunrn n = frequency(LV, fuel);

}```
But the code given in the answer was

Java Code:
```static int NbModeles(String fuel){
int n = 0;
Iterator it = Moteur.ListeMoteurs.iterator();
While(it.hasNext()) if (((Moteur)it.next()).carburant.equals(carburant))n++;
return n;
}```
I think I understand that I should have used
Java Code:
`Moteur.ListeMoteurs`
but I'm not quite sure why...
I thin I didn't understood what we were talking about here... So should I have guessed we where talking about
Java Code:
`Moteur.ListeMoteurs`
?

2. ## Re: How to count the number of an element using an argument?

Do you have a specific java programming question?