Skip to content

Instantly share code, notes, and snippets.

@kmbenjel
Last active August 23, 2025 02:14
Show Gist options
  • Select an option

  • Save kmbenjel/5e2581a94c5262cfcc692215672ced1d to your computer and use it in GitHub Desktop.

Select an option

Save kmbenjel/5e2581a94c5262cfcc692215672ced1d to your computer and use it in GitHub Desktop.
A mosques and roads mapper in Java, an Interfaces exercise
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String[] args) {
// Let's map some Riyadh's Mosques and Roads around QSS!
List<Mappable> mappables = new ArrayList<>();
mappables.add(new Mosque("Al-Rajhi", "Al-Jazeera", "Riyadh"));
mappables.add(new Mosque("Uthman Ibn Affan", "Qurtubah", "Riyadh"));
mappables.add(new Mosque("Salam", "Salam Park", "Riyadh"));
mappables.add(new Road("Uthman Ibn Affan Road", "Riyadh"));
mappables.add(new Road("Airport Road", "Riyadh"));
for (var m : mappables)
Mappable.mapIt(m);
}
}
public interface Mappable {
String getLabel();
String getShape();
String getMarker();
String JSON_PROPERTY = """
"properties": {%s} """;
default String toJSON() {
return """
"type": "%s", "label": "%s", "marker": "%s" """.formatted(getShape(), getLabel(), getMarker());
}
static void mapIt(Mappable mappable) {
System.out.println(JSON_PROPERTY.formatted(mappable.toJSON()));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment