Populating an array using user input(JAVA)

ساخت وبلاگ

Vote count: 0

So I have made a 'Student' class which has some data members,and methods....What I want to do is get input from the user using a form and then initialize a student object using the values entered by the user. I used the following code but somehow every Student object has the same values as the last entered user input. Srry for bad English

 //Declared in main class Student1 stu = new Student1(); Student1[] Student1Array = new Student1[200]; int Mcounter =0; //elsewhere in the program private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { int Admno = Integer.parseInt(admTF.getText()); String Name = name.getText(); int Standard = Integer.parseInt((String)(ClassCB.getSelectedItem()); String S = (String)SectionCB.getSelectedItem(); char Section = S.charAt(0); String G = (String)GenderCB.getSelectedItem(); char Gender = G.charAt(0); stu.CreateStudent(Admno,Name,Standard,Section,Gender); Student1Array[Mcounter]=stu; Mcounter++; }
//Student class
public class Student1 {
int standard;
char section ;
void CreateStudent(int n,String s,int c,char sec,char g){ admissionNo=n; name=s; standard=c; section = sec; gender=g; } }

The jButton is called whenever the user makes their entry, I need to populate the Student1Array but can't.

asked 52 secs ago

back soft...
ما را در سایت back soft دنبال می کنید

برچسب : populate array with user input java, نویسنده : استخدام کار backsoft بازدید : 366 تاريخ : شنبه 30 مرداد 1395 ساعت: 22:24