Enum Representation in Java
South Africa is divided into 9 provinces. Below is an enum representation of these provinces with standard two-letter codes:
java
public enum Province {
EASTERN_CAPE("EC"),
FREE_STATE("FS"),
GAUTENG("GP"),
KWAZULU_NATAL("KZN"),
LIMPOPO("LP"),
MPUMALANGA("MP"),
NORTHERN_CAPE("NC"),
NORTH_WEST("NW"),
WESTERN_CAPE("WC");
private final String code;
Province(String code) {
this.code = code;
}
public String getCode() {
return this.code;
}
}
- Each province is assigned a standard two-character code, commonly used in government systems and forms.
- The
getCode()
method provides the abbreviation for integration in systems or UI displays.
SQL Representation for Storing Province Data
Here's the SQL table and insert script for the provinces of South Africa:
sql
-- Table definition for storing provinces of South Africa
CREATE TABLE provinces (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
code CHAR(3) NOT NULL
);
-- Inserting data for South African provinces
INSERT INTO provinces (name, code) VALUES
('Eastern Cape', 'EC'),
('Free State', 'FS'),
('Gauteng', 'GP'),
('KwaZulu-Natal', 'KZN'),
('Limpopo', 'LP'),
('Mpumalanga', 'MP'),
('Northern Cape', 'NC'),
('North West', 'NW'),
('Western Cape', 'WC');
- The
provinces
table holds each province’s name and abbreviation.
- The two- or three-letter codes are based on common abbreviations used in official and postal contexts.