java - How can I add an object to an arraylist of objects -
the purpose add teams arraylist. each team object string name, string division, int wins, , int losses.
import java.util.arraylist; import java.util.arrays; public class default { arraylist<team> teams = new arraylist<team>(); team mavericks = new team("mavericks","southwest",50,32); team rockets = new team("rockets","southwest",56,26); team grizzlies = new team("memphis","southwest",55,27); teams.add(team mavericks); teams.add(team rockets); teams.add(team grizzlies); } class team { string name, division; int win,loss; public team(string n,string d, int w, int l) { this.name = n; this.division = d; this.win = w; this.loss = l; } }
it
teams.add(team mavericks); teams.add(team rockets); teams.add(team grizzlies);
should be
teams.add(mavericks);//here mavericks object teams.add(rockets); teams.add(grizzlies);
Comments
Post a Comment