Last active
August 23, 2025 02:14
-
-
Save kmbenjel/5e2581a94c5262cfcc692215672ced1d to your computer and use it in GitHub Desktop.
A mosques and roads mapper in Java, an Interfaces exercise
This file contains hidden or 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
| 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); | |
| } | |
| } |
This file contains hidden or 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 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