Looping through an arraylist and calling a method against each instance of class

Link to exercise: https://www.codecademy.com/courses/learn-java/projects/java-language-families

I’m trying to create a loop that calls the getInfo() method against each of the listed languages in my ArrayList. I’ve managed to create a loop that prints a String at each iteration but I can’t figure out how to call a method against each object in the list.

There are two child classes called “Mayan” & “SinoTibetan” (as an FYI)


import java.util.ArrayList;
import java.util.Arrays;

class Language {

protected String languageName;
protected int numSpeakers;
protected String regionsSpoken;
protected String wordOrder;

Language (String name, int speakers, String rgnSpoke, String wdOrder) {
this.languageName = name;
this.numSpeakers = speakers;
this.regionsSpoken = rgnSpoke;
this.wordOrder = wdOrder;
}

public void getInfo() {
System.out.println(this.languageName + " is spoken by " + this.numSpeakers + " people mainly in " + this.regionsSpoken + “.”);
System.out.println("The language follows the word order: " + this.wordOrder);
}

public static void main (String args) {
Language spanish = new Language(“Spanish”, 12345, “Central America”, “backwards”);
Mayan kiche = new Mayan(“Ki’che”, 123556);
SinoTibetan chinese = new SinoTibetan(“Mandarin Chinese”, 1298643);
SinoTibetan burmese = new SinoTibetan(“Burmese”, 98876);

**This section below is what I’m having trouble with. **

ArrayList languages = new ArrayList();
languages.add(spanish);
languages.add(kiche);
languages.add(chinese);
languages.add(burmese);

I can’t need help determining which for loop to use AND the syntax to call the getInfo() method
for (Language language : languages) {
languages.getInfo();

}
}

please help! :slight_smile: