import java.util.Scanner;
import java.util.Arrays;
/*
Online Java - IDE, Code Editor, Compiler

Online Java is a quick and easy tool that helps you to build, compile, test your programs online.
*/

public class Main
{
       public static void main(String[] args) {
        
        System.out.println("Welcome to Online IDE!! Happy Coding :)");
        
        char[] acceptedNumerals = new char[]{'M','D','C','L','X', 'V','I'};
         
        int temp=0;
        int number;
     
        boolean noMatch=true;
        int t=0;
        int j;
        int count=0;
        int pos;
        
        Scanner reader=null;
        
        // This is used to ascertain how many digits end user wants
        reader = new Scanner(System.in); // Reading from System.in
        System.out.println("Enter number numerals in the number to be converted to decimal:");
        number=reader.nextInt();
        
        char inputtedNumerals[] = new char[number];
        int [][] posValues = new int [number][2];
        
do
{
reader = new Scanner(System.in); // Reading from System.in
System.out.println("Enter roman numeral " + (count+1) + " :");
inputtedNumerals[count]=reader.next().charAt(0);
count++;

for (j=0; j<inputtedNumerals.length;j++)
{
    for (int k=0; k<acceptedNumerals.length;k++)
    {
    
    if (inputtedNumerals[j]==acceptedNumerals[k])
    {
        System.out.println("value of k:" + k);
        System.out.println("count:" + count);
        
        posValues[count-1][0]=k;             // this is 2D array. count simply increments with array index of the roman numeral in character array 
                                             //the multidimensal aspect will store the value of numeral converted to decimal. 
        switch(k)
        {
            case 0:
                posValues[count-1][1]=1000;
                break;
            
            case 1:
                posValues[count-1][1]=500;
                break;
                
            case 2:
                posValues[count-1][1]=100;
                break;
                
            case 3:
                posValues[count-1][1]=50;
                break;
                
            case 4:
                posValues[count-1][1]=10;
                break;
                
            case 5:
                posValues[count-1][1]=5;
                break;
                
            case 6:
                posValues[count-1][1]=1;
                break;
        }
        
        pos=k;
        System.out.println("Successful roman numeral");
        noMatch=false;
        k=acceptedNumerals.length-1;
    }
    
}

 if (noMatch==true)
    {
       System.out.println("Please input a successful roman numeral");
       count=count-1;
       break;
    }
}

} while (count<inputtedNumerals.length);

String str = String.valueOf(inputtedNumerals);
System.out.println("This will be converted to decimals:" + str);

performConversion pc = new performConversion(acceptedNumerals, inputtedNumerals,posValues);
}
}

class performConversion
{
    char[] inputtedNumerals;
    char[] acceptedNumerals;
    int [][] posValues;
    
    public void converter()
    {
        if (inputtedNumerals.length==1)    // This functions
        {
                System.out.println("Conversion is:" + posValues[0][1]);
        }
        
        // this is 2D array. count simply increments with array index of the roman numeral in character array 
        // the multidimensal aspect at 0 index will store:  index of which numeral i.e  M is 0, D is 1
                             //aspect at 1 index will store:  decimanl conversion
        
        if (inputtedNumerals.length==2)
        {
            if (posValues[0][0]==posValues[1][0])
            {
                
            System.out.println("Conversion is:" + (posValues[0][1] + posValues[1][1]));
            }
            
            if (posValues[0][0]<posValues[1][0])
            {
                
            System.out.println("Incorrect roman numeral entered");
            }
            
            
            
        }
        
    }
    
    public performConversion (char[] aNumerals, char [] inputNumerals, int [][] pValues)
    {
        this.acceptedNumerals=aNumerals;
        this.inputtedNumerals=inputNumerals;
        this.posValues=pValues;
        converter();
    }
}
