✅ Enum Representation in Java
Switzerland is divided into 26 cantons. Below is a Java enum
representing each canton with their standard two-letter canton code:
java
public enum Canton {
AARGAU("AG"),
APPENZELL_INNERRHODEN("AI"),
APPENZELL_AUSSERRHODEN("AR"),
BASEL_LAND("BL"),
BASEL_CITY("BS"),
BERN("BE"),
FRIBOURG("FR"),
GENÈVE("GE"),
GLARUS("GL"),
GRISONS("GR"),
JURA("JU"),
LUCERNE("LU"),
NEUCHÂTEL("NE"),
NIDWALDEN("NW"),
OBWALDEN("OW"),
SCHAFFHAUSEN("SH"),
SCHWYZ("SZ"),
SOLTHURN("SO"),
ST_GALLEN("SG"),
TICINO("TI"),
THURGAU("TG"),
URI("UR"),
VALAIS("VS"),
VAUD("VD"),
ZUG("ZG"),
ZURICH("ZH");
private final String code;
Canton(String code) {
this.code = code;
}
public String getCode() {
return this.code;
}
}
🔹 Notes:
- Each canton is mapped to its unique two-character code, which is widely recognized in administrative systems and geographic data.
- The
getCode()
method provides easy access to the canton abbreviation for database storage or UI display.
✅ SQL Representation for Storing Canton Data
Below is the SQL schema and insert script for storing the 26 cantons of Switzerland:
sql
-- Table definition for Swiss cantons
CREATE TABLE cantons (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
code CHAR(2) NOT NULL
);
-- Insert cantons into the table
INSERT INTO cantons (name, code) VALUES
('Aargau', 'AG'),
('Appenzell Innerrhoden', 'AI'),
('Appenzell Ausserrhoden', 'AR'),
('Basel-Land', 'BL'),
('Basel-City', 'BS'),
('Bern', 'BE'),
('Fribourg', 'FR'),
('Genève', 'GE'),
('Glarus', 'GL'),
('Grisons', 'GR'),
('Jura', 'JU'),
('Lucerne', 'LU'),
('Neuchâtel', 'NE'),
('Nidwalden', 'NW'),
('Obwalden', 'OW'),
('Schaffhausen', 'SH'),
('Schwyz', 'SZ'),
('Solothurn', 'SO'),
('St. Gallen', 'SG'),
('Ticino', 'TI'),
('Thurgau', 'TG'),
('Uri', 'UR'),
('Valais', 'VS'),
('Vaud', 'VD'),
('Zug', 'ZG'),
('Zurich', 'ZH');
This structure makes it easy to handle regional data for Switzerland in Java applications and relational databases.