Enum Representation in Java
Singapore is divided into 5 main regions. Below is an enum representation of these regions (which are often referred to as districts) with their respective codes:
java
public enum Region {
CENTRAL_REGION("CR"),
EAST_REGION("ER"),
WEST_REGION("WR"),
NORTH_REGION("NR"),
SOUTH_REGION("SR");
private final String code;
Region(String code) {
this.code = code;
}
public String getCode() {
return this.code;
}
}
In the code:
- The enum
Region
defines the 5 regions of Singapore along with their respective codes.
- Each region is associated with a two-character abbreviation.
- The
getCode()
method allows you to retrieve the region code.
SQL Representation for Storing District Data
To store the regions (districts) of Singapore in a database, you can create a table and insert the data using the following SQL:
sql
-- Table definition for storing regions of Singapore
CREATE TABLE regions (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
code CHAR(2) NOT NULL
);
-- Inserting data for regions of Singapore
INSERT INTO regions (name, code) VALUES
('Central Region', 'CR'),
('East Region', 'ER'),
('West Region', 'WR'),
('North Region', 'NR'),
('South Region', 'SR');
In the SQL:
- We define a
regions
table with columns id
(auto-incremented), name
(the name of the region), and code
(the abbreviation for the region).
- The
INSERT INTO
statement adds the regions of Singapore along with their respective codes into the table.
This setup ensures that you can efficiently store and query the regions of Singapore, both in your Java application (via enums) and in a relational database system.