Link to home
Start Free TrialLog in
Avatar of shannonrice
shannonrice

asked on

Newbie to Java Programming needs help with calculation

If anyone can give me some direction getting

      String z[] =
          {"x * ([d[0]] / (1 - Math.pow (1 / (1 + [d[0]]), a[0])))",
           "x * ([d[1]] / (1 - Math.pow (1 / (1 + [d[1]]), a[1])))",
           "x * ([d[2]] / (1 - Math.pow (1 / (1 + [d[2]]), a[2])))"};
   
to perform the calculation and then out putting the results in stead of the formula, it would be greatly appreciated.

__________________________________________

When I compile and execute I get:

Response A = 300
Response B = 5660
Response C = $125,000.00

Calculation = x * ([d[0]] / (1 - Math.pow (1 / (1 + [d[0]]), a[0])))
__________________________________________


Here is the part of my code that deals with this:

      String a[] = {"300", "400" "500"};
      String b[] = {"5660", "1880", "884"};
      String c[] = {"2%", "4%", "6%"};
      String d[] = {"0.004166", "0.00333", "0.005"};
      double x = 125000.00;
 

      String z[] =
          {"x * ([d[0]] / (1 - Math.pow (1 / (1 + [d[0]]), a[0])))",
           "x * ([d[1]] / (1 - Math.pow (1 / (1 + [d[1]]), a[1])))",
           "x * ([d[2]] / (1 - Math.pow (1 / (1 + [d[2]]), a[2])))"};
   
               
              int[] AA = new int [2];
              double[] BB = new double [2];
              double [] CC = new double [2];
              double [] DD = new double [2];
             
                         
                for(int i = 0; i == 0; i++)
                {
     
                    //Output
                    System.out.println ("\n Response A  =  " +(a[0]));
                    System.out.println ("   Response B =  " +(c[0]));
                    System.out.println ("   Response C = " +usCFormat.format (x));
         
                    System.out.println ("Calculation = " +(z[0]));
                    System.out.println ("\n");                    
                }
   

then I have this same "for" statement for [1] and [2];



THANKS FOR THE HELP!


SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of shannonrice
shannonrice

ASKER

I have to use an array.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Make sure to remove the quotes in the array (or, to make it easier to read, replace them with parentheses).
Thanks CI-Ia0s and CEHJ!  
>>... and CEHJ!  

Pity that wasn't reflected in a points split ;-)
>>Pity that wasn't reflected in a points split ;-)

Sorry - forget that! (Don't know how i missed that)
Hrmmm... My email said "Good Assist" but here it says mine was the accepted answer... :\ *shrug*
That's normal ;-)