
/*
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 = {'£','$','€'};
       char originalInput;
       
      
      
      double currencies [][] =   {
                                 
                                 {1.00,1.25,1.17},
                                 {0.80,1.00,0.94},
                                 {0.85,1.07,1.00},
                                 
                                  };
      
      double[] conversionUnits = new double[currencies[0].length];
      
       // 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++)
   {
       //NEED SOMETHING IN HERE TO KEEP CONVERSION FACTOR. SO WHEN IT HITS THE k LOOP, IT CAN USE IT TO GET BACK.
       //IT KNOWS HOW TO CONVERT BACK TO J LOOP.
       // SO THIS VALUE HAS TO BE STORED IN J LOOP.
       
       
       column=0;
       
        for (int j=0; j<currencies[0].length; j++)  // the first location will be (0,1), this is £ to $
       {
           System.out.println("In the J loop");
           column=0;
            if (i!=currencies.length-1)
           {
               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 $
      originalInput=currency[i];
      
      
      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("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]);
    
    conversionUnits[j]= currencies[inputCurrency][outputCurrency]; // THIS WILL BE USED IN LOOP K SO THAT IT CAN GET BACK TO I.
    
    //  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
    
     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");
     
     //----------------------------------
     
            for (int k=0; k<currencies[0].length; k++)  // the first location will be (0,1), this is £ to $
       {
           System.out.println("In the K loop");
           column=0;
           
            if (k!=currencies.length-1)
           {
               System.out.println("This is currency k: " + currency[k]);
               System.out.println("This is input: " + input);
               System.out.println("This is output: " + output);
               System.out.println("This is currency i: " + currency[i]);
               System.out.println("This is currency j: " + currency[j]);
               
               
               if (currency[k]==currency[j] || currency[k]==currency[i] || currency[k]==input || currency[k]==output )
               {
                   System.out.println("INSIDE!!!!!");
                   continue;
               }
           }
           
           
   // this is used to find position of the currency on the matrix.
   // although strictly speaking it should be alligned to the table of data
   
      //***********************************
     // NEED EXTREME WORK HERE SINCE IN THE K LOOP, IT SHOULD NOT TRY TO CONVERT AGAIN TO SAME CURRENCY PROCESSED IN IN
     // This is unrealted to   if (currency[k]==currency[j] || currency[k]==currency[i] )
     
     //SO AS PART OF I LOOP, NEED TO STORE COLUMN IN AN ARRAY AND ENSURE THE INPUT CAN NOT BE THE SAME....
     // ALSO AS PART OF THE J LOOP, NEED TO KEEP TRACK OF THE OUTPUTS TO ENSURE IT IS NOT CONVERTED AGAIN TO THESE.....
     //****************************************************************************************************************
     
     
      input=currency[j];  // this will be £
      output=currency[k]; // this will be $
      
      
      // it will use convertedValue from loop j
      System.out.println(input+"  " +convertedValue + " 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("\nCONVERSION**************");
    
    //currency.charAt
    
    System.out.println("This is the initial amount: " + input+ String.format("%.2f",convertedValue));
    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
    
     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])));
     
     
     System.out.println("This is the conversion factor back to original:" + conversionUnits[j]);
     System.out.println(originalInput);
     System.out.println("This is conversion:" + originalInput  +   String.format("%.2f",(convertedValue/conversionUnits[j])));
     
     
     convertedBack =  convertedValue/conversionUnits[j];
     
     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");
     
     
     
     
}
     
     
     
     
     
     
     
     
     
     
     
}
}
     
     
}
}
        