Enum Representation in Java
Samoa is divided into 11 districts. Below is an enum representation of these districts with their respective codes:
java
public enum District {
AIGA("AI"),
ATUA("AT"),
FALEATA("FA"),
PALAULI("PA"),
SATUPAITEA("SA"),
SAVAII("SV"),
VAVAU("VA"),
ILI-ILI("II"),
ULUGA("UL"),
AVAII("AV"),
SAVAII_NORTH("SN");
private final String code;
District(String code) {
this.code = code;
}
public String getCode() {
return this.code;
}
}
In the code:
- The enum
District
defines the 11 districts of Samoa along with their respective codes.
- Each district is associated with a two-character abbreviation.
- The
getCode()
method allows you to retrieve the district code.
SQL Representation for Storing District Data
To store the districts of Samoa in a database, you can create a table and insert the data using the following SQL:
sql
-- Table definition for storing districts of Samoa
CREATE TABLE districts (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
code CHAR(2) NOT NULL
);
-- Inserting data for districts of Samoa
INSERT INTO districts (name, code) VALUES
('Aiga', 'AI'),
('Atua', 'AT'),
('Faleata', 'FA'),
('Palauli', 'PA'),
('Satupa\'itea', 'SA'),
('Savai\'i', 'SV'),
('Vavau', 'VA'),
('Ili-Ili', 'II'),
('Uluga', 'UL'),
('Avaii', 'AV'),
('Savai\'i North', 'SN');
In the SQL:
- We define a
districts
table with columns id
(auto-incremented), name
(the name of the district), and code
(the abbreviation for the district).
- The
INSERT INTO
statement adds the districts of Samoa along with their respective codes into the table.
This setup ensures that you can efficiently store and query the districts of Samoa, both in your Java application (via enums) and in a relational database system.