mercredi 20 janvier 2016

checking if my array elements meet requirements

I need to create a method which checks each element in my array to see if it is true or false, each element holds several values such as mass, formula, area etc for one compound, and in total there are 30 compounds (so the array has 30 elements). I need an algorithm to ask if mass < 50 and area > 5 = true .

My properties class looks like:

public void addProperty (Properties pro )
        {
        if (listSize >=listlength)
        {
        listlength = 2 * listlength;
        TheProperties [] newList = new TheProperties [listlength];
        System.arraycopy (proList, 0, newList, 0, proList.length);
        proList = newList;
        }
        //add new property object in the next position
        proList[listSize] = pro;
        listSize++;

        }

        public int getSize()
        {
        return listSize;
        }
        //returns properties at a paticular position in list numbered from 0
        public TheProperties getProperties (int pos)
        {
        return proList[pos];
        }
        }

and after using my getters/setters from TheProperties I put all the information in the array using the following;

TheProperties tp = new properties();

string i = tp.getMass();
String y = tp.getArea();
//etc
theList.addProperty(tp);

I then used the following to save an output of the file;

    StringBuilder builder = new StringBuilder();

    for (int i=0; i<theList.getSize(); i++)
    {
        if(theList.getProperties(i).getFormatted() != null)
        {
            builder.append(theList.getProperties(i).getFormatted());
            builder.append("\n");
        }
    }           

    SaveFile sf = new SaveFile(this, builder.toString());

I just cant work out how to interrogate each compound individually for whether they reach the value or not, reading a file in and having a value for each one which then gets saved has worked, and I can write an if statement for the requirements to check against, but how to actually check the elements for each compound match the requirements? I am trying to word this best I can, I am still working on my fairly poor java skills.

Aucun commentaire:

Enregistrer un commentaire