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
提交
取消