import java.util.*;public class RoadTrip{ ArrayList<GeoLocation> roadTrip = new ArrayList<GeoLocation>(); double cheat = 0; // Create a GeoLocation and add it to the road trip public void addStop(String name, double latitude, double longitude) { GeoLocation loc = new GeoLocation(name + " ", latitude, longitude); roadTrip.add(loc); } // Get the total number of stops in the trip public int getNumberOfStops() { return roadTrip.size(); } // Get the total miles of the trip public double getTripLength() { double totalDistance = 0; for (int i = 1; i < roadTrip.size(); i++ ) { GeoLocation here = roadTrip.get(i); GeoLocation prev = roadTrip.get(i-1); totalDistance = totalDistance + here.distanceFrom(prev); } return totalDistance; } // Return a formatted toString of the trip public String toString() { int i = 0; String retVal=""; for( Object test: roadTrip) { retVal = retVal + ( i + 1 ) + ". " + test + "\n"; i++; } return retVal; }}當我返回 retVal 時,它返回值粉末彈簧(-110.97168, -110.97168)阿貢 (-149.00134, -149.00134)澤巴(-84.74096, -84.74096)Hyampom(-53.2522, -53.2522)北費爾菲爾德(47.05816, 47.05816)什么時候應該回來粉末彈簧 (70.47312, -110.97168)阿貢 (-12.26804, -149.00134)澤巴 (-3.89922, -84.74096)Hyampom (84.57072, -53.2522)北費爾菲爾德 (73.14154, 47.05816)問題是緯度值出于某種原因等于經度值。編輯:忘記我在搞亂代碼并刪除緯度部分,把它放回去;仍然給出相同的結果
添加回答
舉報
0/150
提交
取消