diff --git a/src/RomanConverter.java b/src/RomanConverter.java new file mode 100644 index 0000000..4af53f5 --- /dev/null +++ b/src/RomanConverter.java @@ -0,0 +1,150 @@ +/* code from 3004570, 3003836 */ + +//all imports for the projects + +package src; +import java.util.*; + +public class RomanConverter { + + public static void main (String[] args) throws InterruptedException { + + // welcome text to the user + System.out.println("Roman Converter"); + System.out.println("Bitte wählen sie eine Option"); + System.out.println("Rom to Dez (1), Dez to Rom (2)"); + + // initilazing the Scanner + Scanner userinput = new Scanner(System.in); + + // for the first question to know which operation to do + int choise = userinput.nextInt(); + + // the result for the end + int result = 0; + + // to calculate with Roman numbers to dez code + + + if (choise == 1) { + + //String for Calc + //String number= userinput.nextLine(); + String number = "XL"; + + for (int i = 0; i < number.length(); i++) { + + if (number.charAt(i) == 'M') { + System.out.println("1000"); + result = result + 1000; + } else if (number.charAt(i) == 'X') { + if (number.charAt(i - 1) == 'I') { + result += 8; + continue; + //jump back to the beginning + } + System.out.println(10); + result = result + 10; + } else if (number.charAt(i) == 'V') { + if (number.charAt(i - 1) == 'I') { + result += 3; + continue; + //jump back to the beginning + } + System.out.println(5); + result = result + 5; + + } else if (number.charAt(i) == 'L') { + // ask if position 1 is I + if (number.charAt(i - 1) == 'I') { + result += 48; + continue; + //jump back to the beginning + } else if (number.charAt(i - 1) == 'X') { + result += 30; + continue; + //jump back to the beginning + } + System.out.println(50); + result = result + 50; + + } else if (number.charAt(i) == 'C') { + System.out.println(100); + result = result + 100; + + } else if (number.charAt(i) == 'D') { + System.out.println(500); + result = result + 500; + + } else if (number.charAt(i) == 'I') { + System.out.println(1); + result = result + 1; + } + + + } + // End of Choise 1 + + } else if (choise == 2) { + //String for Calc + String number = userinput.nextLine(); + while (result >= 1000) { + number += "M"; + result -= 1000; + } + while (result >= 900) { + number += "CM"; + result -= 900; + } + while (result >= 500) { + number += "D"; + result -= 500; + } + while (result >= 400) { + number += "CD"; + result -= 400; + } + while (result >= 100) { + number += "C"; + result -= 100; + } + while (result >= 90) { + number += "XC"; + result -= 90; + } + while (result >= 50) { + number += "L"; + result -= 50; + } + while (result >= 40) { + number += "XL"; + result -= 40; + } + while (result >= 10) { + number += "X"; + result -= 10; + } + while (result >= 9) { + number += "IX"; + result -= 9; + } + while (result >= 5) { + number += "V"; + result -= 5; + } + while (result >= 4) { + number += "IV"; + result -= 4; + } + while (result >= 1) { + number += "I"; + result -= 1; + } + //End of Choise 2 + } + + + // The end of the Programm + System.out.println("Programm beendet"); + } +} diff --git a/src/main.java b/src/main.java deleted file mode 100644 index 7dc4741..0000000 --- a/src/main.java +++ /dev/null @@ -1,43 +0,0 @@ -/* code from 3004570, 3003836 */ - -package src; - -public class main { - public static void main (String[] args) { - System.out.println("Roman Converter"); - - String number = "MMXVI"; - int result=0; - - for(int i=0; i