java - How do I get my Setter to interact with my separate Class? -
this question has answer here:
public class thing { public static void main (string[] args) { //i set veriables , prompt user enter number of names //prompt user first , last name , store names in array of classes arrays.sort(listofname, new comparator<otherclass>()//sort names according last name //code here (which have not issue) (int = 0; i<numname; i++) { ans = joptionpane.showinputdialog(null,"how many students does: \n "+ listofname[i]+ " have"); int val = integer.parseint(ans); otherclass.setnumstudents(val);// in separate class have setnumstudents } for(int = 0; i<numname; i++) { system.out.println(listofname[i]); } }
earlier in program set array store according separate class otherclass
, int numstudents
set 0 initially, after collecting firstname , lastname alphabetize array , inquire how many students each person has. using setter setnumstudents
try change numstudents
stored in array. code error:
non-static method setnumstudents(int) cannot referenced static context otherclass.setnumstudents(val); ^
thank on issue
i think want:
listofname[i].setnumstudents(val);
or along line. java coding conventions have class names @ camel case starting upper case. otherclass
class name? should otherclass
avoid confusion.
i don't know if listofname[i]
correct instance 'listoftutor[i]' need find instance of otherclass
Comments
Post a Comment