Enum Representation in Java
Serbia is divided into 29 districts. Below is an enum representation of these districts with their respective codes:
java
public enum District {
BELGRADE("BE"),
VOJVODINA("VO"),
CENTRAL_SERBIA("CS"),
SOUTH_SERBIA("SS"),
SUMADIJA("SU"),
POMORAVJE("PO"),
MORAVICA("MO"),
BOR("BO"),
ZAJECAR("ZA"),
NIŠ("NI"),
PČINJA("PC"),
JABLANICA("JA"),
TOPLICA("TO"),
RASKA("RA"),
KOSOVO("KO"),
METOHIJA("ME"),
VLASOTINCE("VL"),
NOVI_PAZAR("NP"),
PRIBOJ("PR"),
VLASINA("VA"),
KIKINDA("KI"),
PANČEVO("PA"),
ZRENJANIN("ZR"),
SENTA("SE"),
NOVI_SAD("NS"),
SREMSKA_MITROVICA("SM"),
BANEJCA("BA"),
SUBOTICA("SU");
private final String code;
District(String code) {
this.code = code;
}
public String getCode() {
return this.code;
}
}
In the code:
- The enum
District
defines the 29 districts of Serbia along with their respective codes.
- Each district is associated with a two-character abbreviation.
- The
getCode()
method allows you to retrieve the district code.
SQL Representation for Storing District Data
To store the districts of Serbia in a database, you can create a table and insert the data using the following SQL:
sql
-- Table definition for storing districts of Serbia
CREATE TABLE districts (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
code CHAR(2) NOT NULL
);
-- Inserting data for districts of Serbia
INSERT INTO districts (name, code) VALUES
('Belgrade', 'BE'),
('Vojvodina', 'VO'),
('Central Serbia', 'CS'),
('South Serbia', 'SS'),
('Sumadija', 'SU'),
('Pomoravje', 'PO'),
('Moravica', 'MO'),
('Bor', 'BO'),
('Zajecar', 'ZA'),
('Niš', 'NI'),
('Pčinja', 'PC'),
('Jablanica', 'JA'),
('Toplica', 'TO'),
('Raška', 'RA'),
('Kosovo', 'KO'),
('Metohija', 'ME'),
('Vlasotinac', 'VL'),
('Novi Pazar', 'NP'),
('Priboj', 'PR'),
('Vlasina', 'VA'),
('Kikinda', 'KI'),
('Pančevo', 'PA'),
('Zrenjanin', 'ZR'),
('Senta', 'SE'),
('Novi Sad', 'NS'),
('Sremska Mitrovica', 'SM'),
('Banejca', 'BA'),
('Subotica', 'SU');
In the SQL:
- We define a
districts
table with columns id
(auto-incremented), name
(the name of the district), and code
(the abbreviation for the district).
- The
INSERT INTO
statement adds the districts of Serbia along with their respective codes into the table.
This setup ensures that you can efficiently store and query the districts of Serbia, both in your Java application (via enums) and in a relational database system.