All pastes #460946 Raw Edit

Mine

public text v1 · immutable
#460946 ·published 2007-04-27 12:18 UTC
rendered paste body
/**
* This class creates a currency converter object.
**didn't use* needs java.util.arraylist
* @author Bill Kukowski, Paul Spilane, Phil Bush
*/
class Converter{
        
        private String[][] currencies = new String[2][164]; //164 currencies, main str[][]
 
        private String toCurrency; //input from exchange method
        private String fromCurrency; //input from exchange method
        private float inputAmount;      //input from exchange method
        
        private float toRate;
        private float fromRate;
                
        private String inputName; //input from setRate method
        private float inputRate; //input from setRate method
        
 
        
        private int currencyNumber;
        
        public Converter()
        {
                //generates first array of fractions
                for (int i=0;i<currencies.length;i++)
                {
                        for (int j=0;j<currencies[i].length;j++)
                        {
                                currencies[i][j] = ("0");
                        }
                }
                currencies[0][0] = "usd"; //set first input rate as usd (us dollars)
                currencies[1][0] = "1";
                currencyNumber=1; //start at 1 instead because usd already entered for conversions/ default (no check for multiple currency rates!)
        }
        
        public void setRate(String inputName, float inputRate)
        {
                currencies[0][currencyNumber] = inputName;
                currencies[1][currencyNumber] = Float.toString(inputRate);
                currencyNumber++;
        }
        
        public float exchange(String fromCurrency, String toCurrency, float inputAmount)
        {
                for (int i=0;i<currencies[0].length;i++)
                {
                                if (currencies[0][i]==fromCurrency)
                                        fromRate = Float.parseFloat(currencies[1][i]);        
                }
                
                for (int i=0;i<currencies[1].length;i++)
                {
                                if (currencies[1][i]==toCurrency)
                                        toRate = Float.parseFloat(currencies[1][i]);
                }
                
                
                
          // return statement      
        }
}