arrays - Setting a constructor and few objects in java -


so have class called memorystructure supposed represent support structure object called student has firstname, lastname, age , university.

this trouble part:

public class memorystructure {       private student[] memoryarray;       private int currentsize;      private int arraysize;       // constructor goes here       /**       * adds object <code>student</code> collection right after       * last element in current collection.       *       * @param student       * object added collection.      */       public void add(student student) {       // done 

can @ least go bit through explaining should write here? it's first touch java , having bit of trouble.

also, should student made class constructor , setters/getters changing through memoryarray in above class?

i supposed make new array once currentarray size gets bigger arraysize, should 2*arraysize , have elements previous array copied in. put in constructor?

i hope question isn't broad.

epoch's answer use list better approach if you're not restricted using arrays. anyway, hope i'm not spoiling fun of learning language posting code.

it should this

public void add(student student) {    // assuming currentsize = 0 , arraysize = *something* in constructor ,    memoryarray = new student[*something*]    if(currentsize == arraysize){       arraysize = arraysize*2;       memoryarray = arrays.copyof(memoryarray, arraysize);    }    memoryarray[currentsize] = student;    currentsize++; } 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -