
/*
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 :)");
        
        
        System.out.println("This will be simple example at moment demonstrating if there is arbitrage");
        System.out.println("To keep it simple, it will compare each currency against only one other currency");
        
        //int [][][] all Conversions = new int[]()
        
        // not sure how to store the integer arrays into a larger container..
        // perhaps create a 3d array... but not worrying at moment.
        
        // this is to verify no arbitrage
       
       // this is the same on horizontal and vertical
       // This is not the best measure since if the position varies on the matrix, it will fail.
       // However if this is introduced in the array, it will be heterogenous elements.
       // Will need to use an object or similar.......
       //and perform conversions to doubles.....
       
       char[] currency = {'£','$','€'};
       
      
       double currencies [][] =   {
                                 
                                 {1.00,1.25,1.17},
                                 {0.80,1.00,0.94},
                                 {0.85,1.07,1.00},
                                 
                                  };
      
       // since no indication of which currency is which, it will use indexof- at first index of 2d array.
      
      // determine which row to use
      //This is taken to be user inputs from Scanner. To be implemented later
      
      // This will first execute to test a single conversion from one currency to another and back again
      // it will be tested in normal conditions and then in arbitrage
      
      
      // NORMAL CONDITIONS ************************
      
      int count=0;
 
      char input = '£';
      char output = '$';
      double amount = 3.00;
      int inputRow=0;
      int outputRow=0;
      
      int column=0;
      int inputCurrency=0;
      int outputCurrency=0;
      
     double convertedValue=0;
     double convertedBack=0;
      
   
   
   for (int i=0; i<currencies[0].length; i++)
   {
       column=0;
       
        for (int j=0; j<currencies[0].length; j++)  // the first location will be (0,1), this is £ to $
       {
           column=0;
            if (i!=currencies.length)
           {
               if (currency[i]==currency[j])
               {
                   j++;
               }
           }
           
           
   // this is used to find position of the currency on the matrix.
   // although strictly speaking it should be alligned to the table of data
   
      input=currency[i];  // this will be £
      output=currency[j]; // this will be $
      
      System.out.println(input+"  " +amount + " to be converted to " + output+"\n");
      
      for (char c: currency)
      {
          System.out.println("This is the value of c: " + c);
          
          System.out.println("Converted from: " + input);
          System.out.println("Converted to: " + output);
          
          if (c==output)   // in this test case $
          {
              System.out.println("***Output****");
              System.out.println("Detected a: " + output + " in row: " + (column));
              
              outputCurrency=column;
          }
          
          if (c==input)  // in this test case £
          {
              System.out.println("***Input***");
              System.out.println("Detected a: " + input + " in column: " + (column));
              
              inputCurrency=column;
              
          }
          column++;
      }
    
    System.out.println("CONVERSION**************");
    
    //currency.charAt
    System.out.println("inputColumn is: " + inputCurrency);
    System.out.println("outputRow is:" + outputCurrency);
    
    System.out.println("This is the initial amount: " + input+ String.format("%.2f",amount));
    System.out.println("This is the conversion factor:" + currencies[outputCurrency][inputCurrency]);
   
     System.out.println("This is conversion:" + output  + String.format("%.2f",(amount/currencies[outputCurrency][inputCurrency] )));
     
     convertedValue = (amount / currencies[outputCurrency][inputCurrency]);
    
    
    //  NEED EXTRA CODE HERE TO TAKE IT BETWEEN ADDITIONAL CURRENCIES (PERHAPS ANOTHER FOR LOOP)
    // BUT THIS TIME IT HAS TO SKIP IF ITS THE SAME CURRENCY OR IF IT IS THE CURRENCY PROCESSED ABOVE.
    // THE PREVIOUS CURRENCY PROCESSED WILL BE POSITION AT C.  THERE IS UCCRENLT NOT INDEX NOTATION DUE TO FOR EACH LOOP
    // THE COLUMN VARIABLE REFERS TO INITIAL CURRENCY.
    
    
    
     System.out.println("This is the conversion factor:" + currencies[inputCurrency][outputCurrency]);
     System.out.println("This is conversion:" + input  +   String.format("%.2f",(convertedValue/currencies[inputCurrency][outputCurrency])));
     
     convertedBack =  convertedValue/currencies[inputCurrency][outputCurrency];
     
     if (convertedBack>amount)
     {
         System.out.println("************ARBITRAGE.....***********");
         System.out.println("Difference of: " + (convertedBack - amount));
     }
     
      if (convertedBack<amount)
     {
         System.out.println("************LOSS OF CURRENCY.....***********");
         System.out.println("Difference of: " + (amount - convertedBack));
     }
     
     
     System.out.println("\n\n");
}
}
     
     
}
}
        