After starting to write a this simple program I have encountered a logic error that I would love explained. The toString()
method is currently printing geographylist.GeographyList@15db9742
Test Class-
public static void main(String[] args) {
GeographyList g = new GeographyList();
g.addCountry ("Scotland");
g.addCountry ("Wales");
g.addCountry ("Ireland");
g.addCountry ("Italy");
System.out.println(g.toString());
ArrayList setup
public class GeographyList {
private ArrayList<String> countries;
public GeographyList(){
countries = new ArrayList<>();
}
public ArrayList<String> getCountries() {
return countries;
}
public String getCountry(int index){
return countries.get(index);
}
public void addCountry(String aCountry){
countries.add(aCountry);
System.out.println(aCountry + " added.");
}