嗨,大家好,抱歉,如果這是一個常見的和令人討厭的問題,我試圖做一個父類(3個單獨的類),但我真的不知道該從哪裏去。創建和比較兒童類
我需要它們在0 < = x < = 100和0 < = y < = 100的限制範圍內隨機產卵,並且不能超過1個小數點。 (我將需要能夠比較'兒童'班級彼此之間的距離)。
或者我不需要3個新班級,但是我可以在同一班級完成所有任務嗎?
如果您認爲我需要,也請隨時添加建議。
TIA
public class Soldier {
public static void main(String args[]) {
Random random = new Random();
double max = 100; //sets the limit to 100 for the soldiers spawn
double min = 0; //sets the minimum to 0 for the soldiers spawn
double xPos = Math.random() * (max - min) - min;//for the x coordinate of the soldiers position
double yPos = Math.random() * (max - min) - min; //for the y coordinate of the soldiers position
xPos = Math.round(xPos * 10)/10.0d; //making sure the x value is to 1dp
yPos = Math.round(yPos * 10)/10.0d; //making sure the y value is to 1dp
System.out.println("(" + xPos + " ," + yPos + ")"); //printing out the position of the soldier (x, y)
}
}
你的問題似乎至少包括3個問題,其中0個問題表達得足夠清楚,足以給你一個正確的答案。你試圖解決的實際問題是什麼?是什麼讓你思考孩子班? – zapl