diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..9a3a92c --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +NumbertoRomanNumerals \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..74441d2 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/discord.xml b/.idea/discord.xml new file mode 100644 index 0000000..d8e9561 --- /dev/null +++ b/.idea/discord.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_dlsc_formsfx_formsfx_core_11_3_2.xml b/.idea/libraries/Maven__com_dlsc_formsfx_formsfx_core_11_3_2.xml new file mode 100644 index 0000000..aef380c --- /dev/null +++ b/.idea/libraries/Maven__com_dlsc_formsfx_formsfx_core_11_3_2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_apiguardian_apiguardian_api_1_1_2.xml b/.idea/libraries/Maven__org_apiguardian_apiguardian_api_1_1_2.xml new file mode 100644 index 0000000..6ac1c42 --- /dev/null +++ b/.idea/libraries/Maven__org_apiguardian_apiguardian_api_1_1_2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_controlsfx_controlsfx_11_1_0.xml b/.idea/libraries/Maven__org_controlsfx_controlsfx_11_1_0.xml new file mode 100644 index 0000000..86b7171 --- /dev/null +++ b/.idea/libraries/Maven__org_controlsfx_controlsfx_11_1_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_8_1.xml b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_8_1.xml new file mode 100644 index 0000000..4910ca9 --- /dev/null +++ b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_8_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_engine_5_8_1.xml b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_engine_5_8_1.xml new file mode 100644 index 0000000..85ab9ad --- /dev/null +++ b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_engine_5_8_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_8_1.xml b/.idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_8_1.xml new file mode 100644 index 0000000..3417208 --- /dev/null +++ b/.idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_8_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_junit_platform_junit_platform_engine_1_8_1.xml b/.idea/libraries/Maven__org_junit_platform_junit_platform_engine_1_8_1.xml new file mode 100644 index 0000000..f19b408 --- /dev/null +++ b/.idea/libraries/Maven__org_junit_platform_junit_platform_engine_1_8_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_openjfx_javafx_base_17_0_1.xml b/.idea/libraries/Maven__org_openjfx_javafx_base_17_0_1.xml new file mode 100644 index 0000000..fd8b69b --- /dev/null +++ b/.idea/libraries/Maven__org_openjfx_javafx_base_17_0_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_openjfx_javafx_base_mac_17_0_1.xml b/.idea/libraries/Maven__org_openjfx_javafx_base_mac_17_0_1.xml new file mode 100644 index 0000000..605f1a8 --- /dev/null +++ b/.idea/libraries/Maven__org_openjfx_javafx_base_mac_17_0_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_openjfx_javafx_controls_17_0_1.xml b/.idea/libraries/Maven__org_openjfx_javafx_controls_17_0_1.xml new file mode 100644 index 0000000..5f64e39 --- /dev/null +++ b/.idea/libraries/Maven__org_openjfx_javafx_controls_17_0_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_openjfx_javafx_controls_mac_17_0_1.xml b/.idea/libraries/Maven__org_openjfx_javafx_controls_mac_17_0_1.xml new file mode 100644 index 0000000..df53e5f --- /dev/null +++ b/.idea/libraries/Maven__org_openjfx_javafx_controls_mac_17_0_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_openjfx_javafx_fxml_17_0_1.xml b/.idea/libraries/Maven__org_openjfx_javafx_fxml_17_0_1.xml new file mode 100644 index 0000000..069c73f --- /dev/null +++ b/.idea/libraries/Maven__org_openjfx_javafx_fxml_17_0_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_openjfx_javafx_fxml_mac_17_0_1.xml b/.idea/libraries/Maven__org_openjfx_javafx_fxml_mac_17_0_1.xml new file mode 100644 index 0000000..4b3a9bd --- /dev/null +++ b/.idea/libraries/Maven__org_openjfx_javafx_fxml_mac_17_0_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_openjfx_javafx_graphics_17_0_1.xml b/.idea/libraries/Maven__org_openjfx_javafx_graphics_17_0_1.xml new file mode 100644 index 0000000..13b8fdb --- /dev/null +++ b/.idea/libraries/Maven__org_openjfx_javafx_graphics_17_0_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_openjfx_javafx_graphics_mac_17_0_1.xml b/.idea/libraries/Maven__org_openjfx_javafx_graphics_mac_17_0_1.xml new file mode 100644 index 0000000..b3763ba --- /dev/null +++ b/.idea/libraries/Maven__org_openjfx_javafx_graphics_mac_17_0_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_opentest4j_opentest4j_1_2_0.xml b/.idea/libraries/Maven__org_opentest4j_opentest4j_1_2_0.xml new file mode 100644 index 0000000..fbc1b16 --- /dev/null +++ b/.idea/libraries/Maven__org_opentest4j_opentest4j_1_2_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..f02cc57 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..25f7df3 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/DecimaltoRomanNumerals.iml b/DecimaltoRomanNumerals.iml new file mode 100644 index 0000000..abc6aaf --- /dev/null +++ b/DecimaltoRomanNumerals.iml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..8a34fec --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +# Decimal to Roman Numerals converter +☕️ - Project to learn how to make an interface to convert Decimal to Roman numerals + +## Where are the most important files located? + +```bash +$ +``` + +## Explainations +This repository is the result of a school exercise and of a sprint of 1 week to learn Java and to apply some bases. + +## License +[MIT](https://choosealicense.com/licenses/mit/) + +## Quality certification +[![CodeFactor](https://www.codefactor.io/repository/github/CodingFactory-Repos/JavaFX-Decimal-to-Roman-numerals/badge)](https://www.codefactor.io/repository/github/CodingFactory-Repos/JavaFX-Decimal-to-Roman-numerals) diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..3981e57 --- /dev/null +++ b/pom.xml @@ -0,0 +1,92 @@ + + + 4.0.0 + + me.loule + DecimaltoRomanNumerals + 1.0-SNAPSHOT + DecimaltoRomanNumerals + + + UTF-8 + 5.8.1 + + + + + org.openjfx + javafx-controls + 17.0.1 + + + org.openjfx + javafx-fxml + 17.0.1 + + + org.controlsfx + controlsfx + 11.1.0 + + + com.dlsc.formsfx + formsfx-core + 11.3.2 + + + org.openjfx + * + + + + + org.junit.jupiter + junit-jupiter-api + ${junit.version} + test + + + org.junit.jupiter + junit-jupiter-engine + ${junit.version} + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 17 + 17 + + + + org.openjfx + javafx-maven-plugin + 0.0.8 + + + + default-cli + + me.loule.decimaltoromannumerals/me.loule.decimaltoromannumerals.Main + + app + app + app + true + true + true + + + + + + + \ No newline at end of file diff --git a/src/main/java/me/loule/decimaltoromannumerals/Main.java b/src/main/java/me/loule/decimaltoromannumerals/Main.java new file mode 100644 index 0000000..f3a90b8 --- /dev/null +++ b/src/main/java/me/loule/decimaltoromannumerals/Main.java @@ -0,0 +1,23 @@ +package me.loule.decimaltoromannumerals; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Scene; +import javafx.stage.Stage; + +import java.io.IOException; + +public class Main extends Application { + @Override + public void start(Stage stage) throws IOException { + FXMLLoader fxmlLoader = new FXMLLoader(Main.class.getResource("Main.fxml")); + Scene scene = new Scene(fxmlLoader.load()); + stage.setTitle("Decimal to Roman Numerals Converter"); + stage.setScene(scene); + stage.show(); + } + + public static void main(String[] args) { + launch(); + } +} \ No newline at end of file diff --git a/src/main/java/me/loule/decimaltoromannumerals/controller/MainController.java b/src/main/java/me/loule/decimaltoromannumerals/controller/MainController.java new file mode 100644 index 0000000..48165b4 --- /dev/null +++ b/src/main/java/me/loule/decimaltoromannumerals/controller/MainController.java @@ -0,0 +1,42 @@ +package me.loule.decimaltoromannumerals.controller; + +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.control.TextField; +import me.loule.decimaltoromannumerals.model.DecimalToRoman; +import me.loule.decimaltoromannumerals.model.RomanToDecimal; + +import java.net.URL; +import java.util.Objects; +import java.util.ResourceBundle; + +public class MainController implements Initializable { + @FXML + private TextField textFieldDecimal; + + @FXML + private TextField textFieldRomainNumerals; + + @Override + public void initialize(URL location, ResourceBundle resources) { + textFieldDecimal.setOnKeyReleased(event -> { + if (!Objects.equals(textFieldDecimal.getText(), "") && Integer.parseInt(textFieldDecimal.getText()) <= 3999) { + DecimalToRoman decimalToRoman = new DecimalToRoman(Integer.parseInt(textFieldDecimal.getText())); + + textFieldRomainNumerals.setText(decimalToRoman.result()); + } else { + textFieldRomainNumerals.setText(""); + } + }); + + textFieldRomainNumerals.setOnKeyReleased(event -> { + if (!Objects.equals(textFieldRomainNumerals.getText(), "") && textFieldRomainNumerals.getText().length() <= 3999) { + RomanToDecimal romanToDecimal = new RomanToDecimal(textFieldRomainNumerals.getText()); + + textFieldDecimal.setText(String.valueOf(romanToDecimal.result())); + } else { + textFieldDecimal.setText(""); + } + }); + } +} \ No newline at end of file diff --git a/src/main/java/me/loule/decimaltoromannumerals/model/DecimalToRoman.java b/src/main/java/me/loule/decimaltoromannumerals/model/DecimalToRoman.java new file mode 100644 index 0000000..cc5826f --- /dev/null +++ b/src/main/java/me/loule/decimaltoromannumerals/model/DecimalToRoman.java @@ -0,0 +1,32 @@ +package me.loule.decimaltoromannumerals.model; + +public class DecimalToRoman { + private static final String[] romanNumerals = {"I", "V", "X", "L", "C", "D", "M"}; + private static final int[] decimalNumerals = {1, 5, 10, 50, 100, 500, 1000}; + private int decimal; + + public DecimalToRoman(int decimal) { + this.decimal = decimal; + } + + public int getDecimal() { + return decimal; + } + + public void setDecimal(int decimal) { + this.decimal = decimal; + } + + public String result() { + String roman = ""; + + for (int i = decimalNumerals.length - 1; i >= 0; i--) { + while (this.decimal >= decimalNumerals[i]) { + roman += romanNumerals[i]; + this.decimal -= decimalNumerals[i]; + } + } + + return roman; + } +} diff --git a/src/main/java/me/loule/decimaltoromannumerals/model/RomanToDecimal.java b/src/main/java/me/loule/decimaltoromannumerals/model/RomanToDecimal.java new file mode 100644 index 0000000..6076d38 --- /dev/null +++ b/src/main/java/me/loule/decimaltoromannumerals/model/RomanToDecimal.java @@ -0,0 +1,34 @@ +package me.loule.decimaltoromannumerals.model; + +public class RomanToDecimal { + private static final String[] romanNumerals = { "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I" }; + private static final int[] decimalNumerals = { 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 }; + private String romanNumeral; + + public RomanToDecimal(String romanNumeral) { + this.romanNumeral = romanNumeral; + } + + public String getRomanNumeral() { + return romanNumeral; + } + + public void setRomanNumeral(String romanNumeral) { + this.romanNumeral = romanNumeral; + } + + public int result() { + int decimal = 0; + int i = 0; + + while (i < romanNumerals.length) { + if (this.romanNumeral.startsWith(romanNumerals[i])) { + decimal += decimalNumerals[i]; + this.romanNumeral = this.romanNumeral.substring(romanNumerals[i].length()); + } else { + i++; + } + } + return decimal; + } +} diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java new file mode 100644 index 0000000..55844ef --- /dev/null +++ b/src/main/java/module-info.java @@ -0,0 +1,12 @@ +module me.loule.decimaltoromannumerals { + requires javafx.controls; + requires javafx.fxml; + + requires org.controlsfx.controls; + requires com.dlsc.formsfx; + + opens me.loule.decimaltoromannumerals to javafx.fxml; + exports me.loule.decimaltoromannumerals; + exports me.loule.decimaltoromannumerals.controller; + opens me.loule.decimaltoromannumerals.controller to javafx.fxml; +} \ No newline at end of file diff --git a/src/main/resources/me/loule/decimaltoromannumerals/Main.fxml b/src/main/resources/me/loule/decimaltoromannumerals/Main.fxml new file mode 100644 index 0000000..5c98d1e --- /dev/null +++ b/src/main/resources/me/loule/decimaltoromannumerals/Main.fxml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/target/classes/me/loule/decimaltoromannumerals/Main.fxml b/target/classes/me/loule/decimaltoromannumerals/Main.fxml new file mode 100644 index 0000000..5c98d1e --- /dev/null +++ b/target/classes/me/loule/decimaltoromannumerals/Main.fxml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + +