Thursday 15 April 2010

java - Trouble with getting area of figure -



java - Trouble with getting area of figure -

import java.util.scanner; public class hw4problem1 { public static void main(string[] args) { scanner input = new scanner(system.in); double x1 = 35.2270869; double y1 = -80.8431267; double x2 = 32.0835407; double y2 = -81.0998342; double x3 = 28.5383355; double y3 = -81.3792365; double x4 = 33.7489954; double y4 = -84.3879824; //radius*************************] double radius= 6731.01; // distance=(radius)arccos(sin(x1)sin(x2)+cos(x1)cos(x2)cos( y1−y2)) double charlottetosavannah = (radius)* math.acos(math.sin(x1) * math.sin(x2)+ math.cos(x1) * math.cos(x2) * math.cos(y1 - y2)); double savannahtoatlanta = (radius) * math.acos(math.sin(x2) * math.sin(x4) + math.cos(x2) * math.cos(x4) * math.cos(y2 - y4)); // distance // distance=(radius)arccos(sin(x1)sin(x2)+cos(x1)cos(x2)cos( y1−y2)) double atlantatocharlotte= (radius) * math.acos(math.sin(x4) * math.sin(x1) + math.cos(x4) * math.cos(x1) * math.cos(y4 - y1)); // ******************************************************************************2 double savannahtoorlando = (radius) * math.acos(math.sin(x2) * math.sin(x3) + math.cos(x2) * math.cos(x3) * math.cos(y2 - y3)); double orlandotoatlanta = (radius) * math.acos(math.sin(x3) * math.sin(x4) + math.cos(x3) * math.cos(x4) * math.cos(y3 - y4)); double atlantatosavannah = (radius) * math.acos(math.sin(x4) * math.sin(x2) + math.cos(x4) * math.cos(x2) * math.cos(y4 - y2)); // system.out.println("distance: "+distance03); double rodistance1 = (charlottetosavannah); double rodistance2 = (savannahtoatlanta); double rodistance3 = (atlantatocharlotte); double rodistance01 = (savannahtoorlando); double rodistance02 = (orlandotoatlanta); double rodistance03 = (atlantatosavannah); double s1 = (rodistance1 + rodistance2 + rodistance3) / 2; double s2 = (rodistance01 + rodistance02 + rodistance03) / 2; //=√ s(s−side 1)(s−side 2)(s−side3) double area1 = math.sqrt(s1 * (s1 - rodistance1) * (s1 - rodistance2) * (s1 - rodistance3)); double area2 = math.sqrt(s2 * (s2 - rodistance01) * (s2 - rodistance02) * (s2 - rodistance03)); double totalarea = (area1 + area2); system.out.println("the area is: " + totalarea); } }

compute area of land surrounded polygon created these cities.

radius: 6,371.01 km s= (side 1+side 2+side3)/2 area_of_triangle=√ s(s−side 1)(s−side 2)(s−side3)

i having problem programme geting wrong answer, getting 7.048521505923942e7 after changing scale 3 , rounding 17516629.000 should be: 117863.342 seek different ways , still getting same answers.

java

No comments:

Post a Comment