java - Arraylist with multiple objects -
i supposed include both string , integer in arraylist. made separate class both types of objects , used arraylist on results in errors.
class:
public class data { private string name; private int age; data(string n,int a) { name = n; age = a; } public string getname() { return(name); } public void setname(string n) { name = n; } public int getage() { return(age); } public void setage(int a) { age = a; } public void print() { system.out.print(("("+getname())); system.out.print(","); system.out.print(getage()); system.out.print(") "); } }
another class arraylist:
import java.util.arraylist; public class cslab { arraylist<data> arlist = new arraylist<data>(); arlist.add(new data("mark", 31)); arlist.add(new data("joe", 13)); arlist.add(new data("rob", 32)); }
i don't think have include main since still results in same errors regardless of inclusion or not.
}
you didn't error got, yes, need main; can't have code in middle of class that:
public class cs1702_lab5 { public static void main(string[] args) { arraylist<data> arlist = new arraylist<data>(); arlist.add(new data("mark", 31)); arlist.add(new data("joe", 13)); arlist.add(new data("rob", 32)); } }
hopefully addresses error got. if it's different error, post error , can deal that.
Comments
Post a Comment