Enum Representation in Java
Rwanda is divided into 4 provinces and the capital city Kigali. Below is an enum representation of these provinces with their respective codes:
java
public enum Province {
EASTERN("EA"),
KIGALI("KI"),
NORTHERN("NO"),
WESTERN("WE"),
SOUTHERN("SO");
private final String code;
Province(String code) {
this.code = code;
}
public String getCode() {
return this.code;
}
}
In the code:
- The enum
Province
defines the 4 provinces of Rwanda along with their respective codes.
- Each province is associated with a two-character abbreviation.
- The
getCode()
method allows you to retrieve the province code.
SQL Representation for Storing Province Data
To store the provinces of Rwanda in a database, you can create a table and insert the data using the following SQL:
sql
-- Table definition for storing provinces of Rwanda
CREATE TABLE provinces (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
code CHAR(2) NOT NULL
);
-- Inserting data for provinces of Rwanda
INSERT INTO provinces (name, code) VALUES
('Eastern', 'EA'),
('Kigali', 'KI'),
('Northern', 'NO'),
('Western', 'WE'),
('Southern', 'SO');
In the SQL:
- We define a
provinces
table with columns id
(auto-incremented), name
(the name of the province), and code
(the abbreviation for the province).
- The
INSERT INTO
statement adds the provinces of Rwanda along with their respective codes into the table.
This setup ensures that you can efficiently store and query the provinces of Rwanda, both in your Java application (via enums) and in a relational database system.