/* Manipulations sur une classe */ /* coordonnees GPS */ public class ManipulationCoordonneesGPS { /* Type agrege de stockage des informations */ /* relatives a une localisation codee */ /* sous la forme degres, minutes, secondes */ static class Localisation { int d = 0; int mn = 0; double s = 0.0; }; /* Type agrege de stockage des informations */ /* relatives a une localisation GPS */ static class LocalisationGPS { Localisation lon = new Localisation(); Localisation lat = new Localisation(); }; /* Programme principal */ public static void main(String [] args) { LocalisationGPS l1 = new LocalisationGPS(); LocalisationGPS l2 = new LocalisationGPS(); //l1.lon.d = -90; //l1.lon.mn = 30; //l1.lon.s = 10.0; //l1.lat.d = 0; //l1.lat.mn = 0; //l1.lat.s = 0.0; //l2.lon.d = 90; //l2.lon.mn = 30; //l2.lon.s = 10.0; //l2.lat.d = 0; //l2.lat.mn = 0; //l2.lat.s = 0.0; Ecran.afficherln("SVP, P1?"); Ecran.afficherln("Longitude :"); l1.lon.d = Clavier.saisirInt(); l1.lon.mn = Clavier.saisirInt(); l1.lon.s = Clavier.saisirDouble(); Ecran.afficherln("Latitude :"); l1.lat.d = Clavier.saisirInt(); l1.lat.mn = Clavier.saisirInt(); l1.lat.s = Clavier.saisirDouble(); Ecran.afficherln("SVP, P2?"); Ecran.afficherln("Longitude :"); l2.lon.d = Clavier.saisirInt(); l2.lon.mn = Clavier.saisirInt(); l2.lon.s = Clavier.saisirDouble(); Ecran.afficherln("Latitude :"); l2.lat.d = Clavier.saisirInt(); l2.lat.mn = Clavier.saisirInt(); l2.lat.s = Clavier.saisirDouble(); double lo1 = l1.lon.d+((l1.lon.s/60.0)+l1.lon.mn)/60.0; double lo2 = l2.lon.d+((l2.lon.s/60.0)+l2.lon.mn)/60.0; double la1 = l1.lat.d+((l1.lat.s/60.0)+l1.lat.mn)/60.0; double la2 = l2.lat.d+((l2.lat.s/60.0)+l2.lat.mn)/60.0; lo1 = lo1*Math.PI/180.0; lo2 = lo2*Math.PI/180.0; la1 = la1*Math.PI/180.0; la2 = la2*Math.PI/180.0; double dlo = (lo2-lo1)/2.0; double dla = (la2-la1)/2.0; double a = (Math.sin(dla)*Math.sin(dla))+Math.cos(la1)*Math.cos(la2)*(Math.sin(dlo)*Math.sin(dlo)); double distance = 2.0 * Math.atan2(Math.sqrt(a),Math.sqrt(1.0-a)) * 6378.137; Ecran.afficherln(lo1); Ecran.afficherln(lo2); Ecran.afficherln(la1); Ecran.afficherln(la2); Ecran.afficherln("Distance : ",distance); } }