Enum Representation in Java
Qatar is divided into 8 municipalities. Below is an enum representation of those municipalities with their respective codes:
java
public enum Municipality {
AL_DAAYEN("DA"),
AL_KHOR("KH"),
AL_SHAHANIYA("SH"),
AL_WAKRAH("WA"),
DOHA("DO"),
UMM_SALAL("US");
private final String code;
Municipality(String code) {
this.code = code;
}
public String getCode() {
return this.code;
}
}
In the code:
- The enum
Municipality
defines the municipalities of Qatar and 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 Qatar in a database, you can create a table and insert the data using the following SQL:
sql
-- Table definition for storing municipalities of Qatar
CREATE TABLE municipalities (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
code CHAR(2) NOT NULL
);
-- Inserting data for municipalities of Qatar
INSERT INTO municipalities (name, code) VALUES
('Al Daayen', 'DA'),
('Al Khor', 'KH'),
('Al Shahaniya', 'SH'),
('Al Wakrah', 'WA'),
('Doha', 'DO'),
('Umm Salal', 'US');
In the SQL:
- We create 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 Qatar along with their respective codes into the table.
This setup ensures that you can efficiently store and query the municipalities of Qatar, both in your Java application (via enums) and in a relational database system.