首先,我的英語很抱歉,我是法語。如何爲多維數組創建一個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 –