Created
January 12, 2023 18:04
-
-
Save dracula151997/f1d1e18a4358f57d2837391c06f2891f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LocationUtil { | |
public static int calculateDistanceInKm(double latitude1, double longitude1, double latitude2, double longitude2) { | |
Location location1 = new Location("location_1"); | |
location1.setLatitude(latitude1); | |
location1.setLongitude(longitude1); | |
Location location2 = new Location("location_2"); | |
location2.setLatitude(latitude2); | |
location2.setLongitude(longitude2); | |
return (int) Math.ceil(location1.distanceTo(location2) / 1000); | |
} | |
public static int calculateDeliveryCost(int distance) { | |
int deliveryCost = 12; | |
if (distance > 3) { | |
for (int i = 4; i <= distance; i++) { | |
deliveryCost += 2; | |
} | |
} | |
return deliveryCost; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment