Solved

Newbie to Java Programming needs help with calculation

Posted on 2004-10-09
9
233 Views
Last Modified: 2010-03-31
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!


0
Comment
Question by:shannonrice
  • 4
  • 3
  • 2
9 Comments
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 250 total points
ID: 12268307
Would it not be better to just use a function?



            int a[] = {300, 400, 500};

            double d[] = {0.004166, 0.00333, 0.005};

            double x = 125000.00;

........


      public static double calc(int n) {
            return x * d[n] / (1 - Math.pow(1 / (1 + d[n]), a[n]));
      }
0
 

Author Comment

by:shannonrice
ID: 12268355
I have to use an array.
0
 
LVL 3

Accepted Solution

by:
CI-Ia0s earned 250 total points
ID: 12268452
Why are all your arrays of type String? I'd suggest making all the arrays with numbers in them of type double or type int as CEHJ suggested. If you want to use an array, just make array z of type double and it'll work fine.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 3

Expert Comment

by:CI-Ia0s
ID: 12268454
Make sure to remove the quotes in the array (or, to make it easier to read, replace them with parentheses).
0
 

Author Comment

by:shannonrice
ID: 12269142
Thanks CI-Ia0s and CEHJ!  
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12270437
>>... and CEHJ!  

Pity that wasn't reflected in a points split ;-)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12270449
>>Pity that wasn't reflected in a points split ;-)

Sorry - forget that! (Don't know how i missed that)
0
 
LVL 3

Expert Comment

by:CI-Ia0s
ID: 12272681
Hrmmm... My email said "Good Assist" but here it says mine was the accepted answer... :\ *shrug*
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12272685
That's normal ;-)
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Tomcat: Unable to run tomcat service. 2 24
ejb mdb examples 1 10
SequenceInputStream example 3 19
Setup GlassFish 4 22
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to implement Singleton Design Pattern in Java.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question