How do I change which attributes to use from an object at runtime?
I am trying to calculate scores based on 4 attributes of objects in an Array. Each object has 8 attributes in total, 4 of which are to be used to calculate the score. I would like to dynamically choose which 4 attributes to be used.
I am thinking something along these lines:
car[] = new car[100];
//populate car array...
String[] mySelectedCarAttributes = new String[];
mySelectedCarAttributes[0]=car.attribute1 //attributes are ints
mySelectedCarAttributes[1]=car.attribute2
mySelectedCarAttributes[2]=car.attribute3
mySelectedCarAttributes[3]=car.attribute4
// the content of mySelectedCarAttributes would be
// dynamically changed by user interaction, so for example:
mySelectedCarAttributes[3]=car.attribute8
for (int i=0;i>car.length;i++){
int calcScore = car[i].mySelectedCarAttributes[0]+
car[i].mySelectedCarAttributes[1]+
car[i].mySelectedCarAttributes[2]+
car[i].mySelectedCarAttributes[3];
Thanks!
Aucun commentaire:
Enregistrer un commentaire