Advertisement
Guest User

Untitled

a guest
May 19th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. public class CoordinateTest {
  2.  
  3. public static void main(String[] args) {
  4. // TODO Auto-generated method stub
  5. int breiten = 0;
  6. int längen = 0;
  7. Coordinates test1 = new Coordinates (170, 60);
  8. Coordinates test2 = new Coordinates (390, 190);
  9.  
  10. System.out.println(test1.getLongitude() + " " + test1.getLatitude());
  11.  
  12. System.out.println(test1.equals(test2));
  13.  
  14. System.out.println(test1);
  15. System.out.println(test2);
  16. while (längen > -1000) {
  17. breiten = breiten -100;
  18. längen = längen - 100;
  19.  
  20. test1.setLatitude(breiten);
  21. test1.setLongitude(längen);
  22.  
  23. System.out.println(test1);
  24.  
  25. }
  26.  
  27. }
  28.  
  29. }
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39. public class Coordinates {
  40. double latitude; //Breitengrad
  41. double longitude; //Längengrad
  42.  
  43.  
  44. public Coordinates (double pLatitude, double pLongitude) {
  45.  
  46. setLongitude(pLongitude);
  47. setLatitude (pLatitude);
  48.  
  49.  
  50. }
  51.  
  52. public double getLatitude () {
  53. return latitude;
  54.  
  55. }
  56.  
  57.  
  58. public double getLongitude () {
  59. return longitude;
  60.  
  61. }
  62.  
  63. public void setLatitude (double pLatitude){
  64.  
  65. while (pLatitude < -90) {
  66. pLatitude = pLatitude + 180;
  67. //latitude = pLatitude;
  68. }
  69. while (pLatitude > 90) {
  70. pLatitude = pLatitude -180;
  71. //latitude = pLatitude;
  72.  
  73. }
  74. latitude = pLatitude;
  75.  
  76. }
  77.  
  78. public void setLongitude (double pLongitude){
  79. while (pLongitude < -180) {
  80. pLongitude = pLongitude + 360;
  81. //longitude = pLongitude;
  82. }
  83. while (pLongitude > 180) {
  84. pLongitude = pLongitude -180;
  85. //longitude = pLongitude;
  86.  
  87. }
  88. longitude = pLongitude;
  89. }
  90.  
  91. public String toString() {
  92.  
  93. return String.format("Breitengrad %s und Längengrad %s",latitude, longitude);
  94. }
  95. public boolean equals (Coordinates pTest) {
  96. if (longitude == pTest.getLongitude() && latitude == pTest.getLatitude()) {
  97. return true;
  98.  
  99. }return false;
  100.  
  101. }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement