java - How do I add a class to an arraylist in processing? -
whenever seek add together country
arraylist<country>
maintain on getting error: unexpected token: (
, highlights countries.add
line. i'm not sure why happening.
class country { private int mland, mwaters; //mtotalborders; private string mcenter; country(int earth, int aqua, string yn) { mland = earth; mwaters = aqua; mcenter = yn; } public int getland() { homecoming mland; } public int getwaters() { homecoming mwaters; } public int gettotalborders() { homecoming mland+mwaters; } public string getcenter() { homecoming mcenter; } } country turkey = new country(16, 7, "no"); country french republic = new country(22, 4, "no"); country england = new country(17, 9, "no"); country federal republic of germany = new country(26, 4, "yes"); country republic of austria = new country(28, 1, "yes"); country italy = new country(17, 8, "yes"); country russian federation = new country(23, 3, "no"); arraylist<country> countries = new arraylist<country>(); countries.add(turkey);
you need set code method - want utilize main
method - see below.
...... public string getcenter() { homecoming mcenter; } public static void main(string[] args){ country turkey = new country(16, 7, "no"); country french republic = new country(22, 4, "no"); country england = new country(17, 9, "no"); country federal republic of germany = new country(26, 4, "yes"); country republic of austria = new country(28, 1, "yes"); country italy = new country(17, 8, "yes"); country russian federation = new country(23, 3, "no"); arraylist<country> countries = new arraylist<country>(); countries.add(turkey); } }
note: proper convention capitalize class
names, , have variable names lowercase.
this require alter class
name in code - see below.
class country { private int mland, mwaters; //mtotalborders; private string mcenter; country(int earth, int aqua, string yn) { ......
also anytime reference class
name. example.
country turkey = new country(16, 7, "no");
java arraylist processing
No comments:
Post a Comment