/*
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 is answer:" + expandedForm(257.24));
    }
    
    public static String expandedForm(Double number)
    {
        String createString=null;
        
        String convertedNumber = Double.toString(number); 
       
        //problem has to be treated as two parts... string before and after decimal place.
        
        int positionDecimalPoint= convertedNumber.indexOf('.');   //zero based notation  it would be 3 in above example
        int remainingChars;
        int roundedNearestUnit;
        int count=1;
        int posAfter=1;
        Double remainingPart=0.0;
        
        String charsBeforeDecimal = convertedNumber.substring(0,positionDecimalPoint);
        String charsAfterDecimal = convertedNumber.substring(positionDecimalPoint+1,convertedNumber.length());
        
        int lengthCharsBeforeDecimal = charsBeforeDecimal.length();
        int lengthCharsAfterDecimal =  charsAfterDecimal.length();
        
        System.out.println(charsBeforeDecimal);
        System.out.println(charsAfterDecimal);
        
        do
        //for (int i=0; i<convertedNumber.length();i++)
        {
            System.out.println("i: " + i);
            
            if (i==positionDecimalPoint)
            {
                System.out.println("Will it do this?");
                
                i++;
            }
            System.out.println("conversion: " + convertedNumber);
            remainingChars = convertedNumber.length();
            
            
            
            
            // when trying to cast, unfortunately it failed to pick up first Character
            // it picked up two characters....
            //int prefix = (int)(convertedNumber.charAt(0));
            
            int prefix;
            
            prefix = Character.getNumericValue(convertedNumber.charAt(0)); 
            System.out.println("prefix22:  " + prefix);
            
            convertedNumber=convertedNumber.substring(1,remainingChars);
            remainingPart = Double.parseDouble(convertedNumber);
            
            
            if (i>positionDecimalPoint)
            {
                int denominator = posAfter * 10;
                char numerator = (char) prefix;
                String format = numerator + "/" + denominator;
                System.out.println("after decimal:" + format);
                
                posAfter++;
                
                return createString + expandedForm(remainingPart);
            }
            
            
            
            if (i<positionDecimalPoint)  // this would be 3 in  257.24
            {
                
                
            //need to create alternate int and round down nearest 100
            //need to know number remaining chars in String
            
            
            // Now remaining characters is used in  10 ^  remainingChars
            // for instance  247  will give  2 x (10 ^ 2) = 200
            
            roundedNearestUnit =  (int) (Math.pow(10,lengthCharsBeforeDecimal-count) * prefix);
            System.out.println("rounded down:" + roundedNearestUnit);
            
            
            
            
            System.out.println("processing: " + convertedNumber);
            count++;
            
            createString = Integer.toString(roundedNearestUnit);
            
            System.out.println("This is remaining part:" + remainingPart);
            
            //int remaining_Part= (int) remainingPart;
            
            // can not perform return statement like this, since it will not be able to
            //perform execution after the .  if the statement evaluates as true....
            return (remainingPart<10) ?   createString + " + " +  (remainingPart)  + expandedForm(remainingPart) :  createString + " + " +  expandedForm(remainingPart);
            
    
        }
        
        
        
    }while(remainingPart.length>1);
        
        
        return null;
        
    }
    
}
