首先,我的英语很抱歉,我是法语。如何为多维数组创建一个getter方法和一个setter方法?
以下是我正在试图通过一个数学符号写这个问题要解决的问题:
我有坐标的夫妻看起来像这样:(x, y)
An = {(Xn;Yn)}
array[An][(Xn;Yn)] = {{X1;Y1}{X2;Y2}...{Xz;Yz}};
在我的程序中,我需要为多维数组创建一个getter和setter。
这是我的代码:
//Infos for animations of objects
//Sorting
Random random1 = new Random();
int obscMin=0, obscMax=4; //I sort them to know how many obstacles will have to be created. obsc is the obstacle
int nbreObsc = obscMin + random1.nextInt(obscMax - obscMin); //nbreObsc is the number of obstacles
//End of sorting
/*Here's the model of a table:
A couple: An={(Xn;Yn)}
Tableau1[An][(Xn;Yn)]={{X1;Y1}{X2;Y2}...{Xz;Yz}};*/
float posObsc [] []=new float [nbreObsc] [2]; //New table, which will contain the positions of the obstacles
//Obstacle position getter and setter
public float[][] getPosObsc(){//getters
return posObsc;
}
public void setPosObsc(float[][] posObsc){//setters
this.posObsc=posObsc;
}
//End of obstacle position getter and setter
protected boolean detruireObsc=false; //"detruireObsc" means "destroyObstacle"
//Algorithm that defines the movement of obstacles
protected void obscDeplacemt(){
for(int i=1;i<=nbreObsc;i++){
//Sorting to determine the Xs
float ordMin=0,ordMax=width;
float ordObsc = ordMin + (float)Math.random() * (ordMax - ordMin); //ordObsc means obstacleXPosition
setPosObsc(posObsc [i][0]);
//End of sorting
}
}
//End of obstacle movement algorithm
这是我从日食出现错误:
The method setPosObsc(float[][]) in the type Activity01Jeux.RenderViewJoueur is not applicable for the arguments (float)
你不介意我翻译的意见成英文? Est-ce-queçavousdérangeraitsi je traduirais vos commentaires du code en Anglais? – Runemoro
请提供可编辑的代码。 –
@ Runemoro // Absolumt pas c'est avec grd plaisir!Traduit traduit et traduit encore:p –