Skip to content

Instantly share code, notes, and snippets.

@dracula151997
Created January 12, 2023 18:04
Show Gist options
  • Save dracula151997/f1d1e18a4358f57d2837391c06f2891f to your computer and use it in GitHub Desktop.
Save dracula151997/f1d1e18a4358f57d2837391c06f2891f to your computer and use it in GitHub Desktop.
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