Reputation: 1
So I've been trying to create a set of cards by defining them through their value then create one class per color. I have a method for creating a list of 13 cards from 2 to ace:
package test;
import java.util.*;
public class Cartes {
void liste_cartes(){
ArrayList liste_cartes = new ArrayList();
for(int i=2; i<15; i++) {
liste_cartes.add(i);
}
}
}
I've tried using this method in my color class !
package test;
import java.util.*;
public class Coeur {
Cartes cartes = new Cartes();
cartes.liste_cartes();
}
However I'm getting an <identifier expected>
error on cartes.liste_cartes();
. Relatively new to Java here, so any help is much appreciated.
Upvotes: 0
Views: 1000
Reputation: 11
For Java program,JVM first looks for main() to run the program. Try writing this:-
public class Coeur {
public static void main(String[] args) {
Cartes cartes = new Cartes();
cartes.liste_cartes();
}
}
Upvotes: 1
Reputation: 5695
Wrap cartes.liste_cartes();
in a method, like
public void dummyMethod(){ //should probably be your main method, if in your main class
cartes.liste_cartes();
}
Also, your ArrayList
is of raw type. Make use of generics.
ArrayList<Integer> liste_cartes = new ArrayList<Integer>();
Upvotes: 0