Enum Representation in Java
Papua New Guinea consists of several provinces. Below is an enum representation of those provinces with their respective codes:
java
public enum Province {
CENTRAL("CP"),
CHIMBU("CM"),
EASTERN_HIGHLANDS("EH"),
GULF("GF"),
MADANG("MD"),
MANUS("MS"),
MILNE_BAY("MB"),
MOROBE("MB"),
NEW_IRLAND("NI"),
NORTHERN("NR"),
SOUTHERN_HIGHLANDS("SH"),
WESTERN("WS");
private final String code;
Province(String code) {
this.code = code;
}
public String getCode() {
return this.code;
}
}
In the code:
- The enum
Province
defines the provinces of Papua New Guinea and their respective codes.
- Each province is associated with a code in the format of a two-character abbreviation.
- The
getCode()
method allows you to retrieve the province code.
SQL Representation for Storing Province Data
You can store the provinces of Papua New Guinea in a database using the following SQL table definition and insert statements:
sql
-- Table definition for storing provinces of Papua New Guinea
CREATE TABLE provinces (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
code CHAR(2) NOT NULL
);
-- Inserting data for provinces of Papua New Guinea
INSERT INTO provinces (name, code) VALUES
('Central', 'CP'),
('Chimbu', 'CM'),
('Eastern Highlands', 'EH'),
('Gulf', 'GF'),
('Madang', 'MD'),
('Manus', 'MS'),
('Milne Bay', 'MB'),
('Morobe', 'MB'),
('New Ireland', 'NI'),
('Northern', 'NR'),
('Southern Highlands', 'SH'),
('Western', 'WS');
In the SQL:
- We define a
provinces
table with id
(auto-incremented), name
(the name of the province), and code
(the abbreviation for the province).
- The
INSERT INTO
statement is used to insert the provinces of Papua New Guinea along with their respective codes into the table.
This approach ensures that the provinces of Papua New Guinea are stored efficiently in a database, and they can be accessed or manipulated easily.