Enum Representation in Java
Romania is divided into 41 counties and the capital city, Bucharest. Below is an enum representation of those counties with their respective codes:
java
public enum County {
ALBA("AB"),
ARAD("AR"),
ARGEȘ("AG"),
BACĂU("BC"),
BIHOR("BH"),
BISTRIȚA_NĂSĂUD("BN"),
BOTOȘANI("BS"),
BRAȘOV("BR"),
BRĂILA("BR"),
BUZĂU("BZ"),
CARAȘ_SEVERIN("CS"),
CĂLĂRAȘI("CL"),
CLUJ("CJ"),
CONSTANȚA("CS"),
COVASNA("CV"),
DÂMBOVIȚA("DB"),
DOLJ("DO"),
GALAȚI("GL"),
GIURGIU("GR"),
GORJ("GO"),
HARGHITA("HR"),
HUNEDOARA("HD"),
IALOMIȚA("IL"),
IAȘI("IS"),
ILFOV("IF"),
MARAMUREȘ("MM"),
MEHEDINȚI("MH"),
MUREȘ("MS"),
NEAMȚ("NT"),
OLT("OT"),
PRAHOVA("PH"),
SĂLAJ("SJ"),
SATU_MARE("SM"),
SIBIU("SB"),
SUCEAVA("SV"),
TELEORMAN("TR"),
TIMIȘ("TM"),
TULCEA("TL"),
VÂLCEA("VS"),
VASLUI("VS"),
VRANCEA("VS");
private final String code;
County(String code) {
this.code = code;
}
public String getCode() {
return this.code;
}
}
In the code:
- The enum
County
defines the counties of Romania and their respective codes.
- Each county is associated with a two-character abbreviation.
- The
getCode()
method allows you to retrieve the county code.
SQL Representation for Storing County Data
To store the counties of Romania in a database, you can create a table and insert the data using the following SQL:
sql
-- Table definition for storing counties of Romania
CREATE TABLE counties (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
code CHAR(2) NOT NULL
);
-- Inserting data for counties of Romania
INSERT INTO counties (name, code) VALUES
('Alba', 'AB'),
('Arad', 'AR'),
('Argeș', 'AG'),
('Bacău', 'BC'),
('Bihor', 'BH'),
('Bistrița-Năsăud', 'BN'),
('Botoșani', 'BS'),
('Brașov', 'BR'),
('Brăila', 'BR'),
('Buzău', 'BZ'),
('Caraș-Severin', 'CS'),
('Călărași', 'CL'),
('Cluj', 'CJ'),
('Constanța', 'CS'),
('Covasna', 'CV'),
('Dâmbovița', 'DB'),
('Dolj', 'DO'),
('Galați', 'GL'),
('Giurgiu', 'GR'),
('Gorj', 'GO'),
('Harghita', 'HR'),
('Hunedoara', 'HD'),
('Ialomița', 'IL'),
('Iași', 'IS'),
('Ilfov', 'IF'),
('Maramureș', 'MM'),
('Mehedinți', 'MH'),
('Mureș', 'MS'),
('Neamț', 'NT'),
('Olt', 'OT'),
('Prahova', 'PH'),
('Sălaj', 'SJ'),
('Satu Mare', 'SM'),
('Sibiu', 'SB'),
('Suceava', 'SV'),
('Teleorman', 'TR'),
('Timiș', 'TM'),
('Tulcea', 'TL'),
('Vâlcea', 'VS'),
('Vaslui', 'VS'),
('Vrancea', 'VS');
In the SQL:
- We define a
counties
table with columns id
(auto-incremented), name
(the name of the county), and code
(the abbreviation for the county).
- The
INSERT INTO
statement adds the counties of Romania along with their respective codes into the table.
This setup ensures that you can efficiently store and query the counties of Romania, both in your Java application (via enums) and in a relational database system.