Enum Representation in Java
San Marino is divided into 9 municipalities. Below is an enum representation of these municipalities with their respective codes:
java
public enum Municipality {
ACQUAVIVA("AQ"),
BORGO_MAGGIORE("BM"),
CHIESANUOVA("CN"),
DOMAGNANO("DO"),
FIORENTINO("FI"),
MILANO("MI"),
MONTGIARDINO("MG"),
SERRAVALLE("SE");
private final String code;
Municipality(String code) {
this.code = code;
}
public String getCode() {
return this.code;
}
}
In the code:
- The enum
Municipality
defines the 9 municipalities of San Marino along with their respective codes.
- Each municipality is associated with a two-character abbreviation.
- The
getCode()
method allows you to retrieve the municipality code.
SQL Representation for Storing Municipality Data
To store the municipalities of San Marino in a database, you can create a table and insert the data using the following SQL:
sql
-- Table definition for storing municipalities of San Marino
CREATE TABLE municipalities (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
code CHAR(2) NOT NULL
);
-- Inserting data for municipalities of San Marino
INSERT INTO municipalities (name, code) VALUES
('Acquaviva', 'AQ'),
('Borgo Maggiore', 'BM'),
('Chiesanuova', 'CN'),
('Domagnano', 'DO'),
('Fiorentino', 'FI'),
('Milano', 'MI'),
('Montegiardino', 'MG'),
('Serravalle', 'SE');
In the SQL:
- We define a
municipalities
table with columns id
(auto-incremented), name
(the name of the municipality), and code
(the abbreviation for the municipality).
- The
INSERT INTO
statement adds the municipalities of San Marino along with their respective codes into the table.
This setup ensures that you can efficiently store and query the municipalities of San Marino, both in your Java application (via enums) and in a relational database system.