Using arrays with formulas

I'm having trouble getting my arrays to work in the formula that I need to use to calculate a monthly mortgage payment, which is what I need to do. I'm supposed to use arrays to store three different term year amounts and three different interest rates, and then display the monthly payment and other info for each amount. Can someone help with this? I keep getting errors that say "cannot use operator / or * with double[]". Here is my code:
class PaymentArray {
     public static void main(String[] arguments) {
          double amount = 100000;
          int[] term = {7, 15, 30};
          double[] rate = {.0535, .055, .0575};
          double payment = (amount*(rate/12))/(1-(Math.pow(1/(1+(rate/12)),(term*12))));
          for (int i = 0; i < term.length; i++) {
               for (int j = 0; j < rate.length; j++) {
                    System.out.println("If the initial loan amount is " + amount);
                    System.out.println("and the length of the term is " + term + " years");
                    System.out.println("and the monthly interest rate is " + rate);
                    System.out.println("The monthly payment will be " + payment);
}Any help would be greatly appreciated. Thanks!!! :-)

That all worked really well, thanks so much!!!
The only problem I have now is, instead of calculating the payments at 7 years/5.35%, 15 years/5.5%, and 30 years/5.75%, it's calculating them for 7 years at 5.35%, 5.5%, and 5.75%, 15 years at 5.35%, 5.5%, and 5.75%, and so on. I don't need it to do all of that, I need the years to correspond to the correct interest rate. How can I change that? Thank you so much. Here is my new code:
class PaymentArray {
     public static void main(String[] arguments) {
          double amount = 100000;
          int[] term = {7, 15, 30};
          double[] rate = {.0535, .055, .0575};
          for (int i = 0; i < term.length; i++) {
               for (int j = 0; j < rate.length; j++) {
                    System.out.println("If the initial loan amount is " + amount);
                    System.out.println("and the length of the term is " + term[i] + " years");
                    System.out.println("and the monthly interest rate is " + rate[j]);
                    double payment = (amount*(rate[j]/12))/(1-(Math.pow(1/(1+(rate[j]/12)),(term*12))));
                    System.out.println("The monthly payment will be " + payment);

Similar Messages

  • Using arrays with the IF conditional

    What Im trying to do is test the value of an variable and see if it exists inside an array. So as a simple example I would do something like this with AppleScript
    set excludeList to {"A", "B"}
    set theItem to "C"
    if theItem is not in excludeList then
    display dialog theItem
    end if
    So how would I replicate that in a shell script. Currently I would just use a long if statement like this
    #!/bin/sh
    theItem="C"
    if [ $theItem != "A" ] && [ $theItem != "B" ]
    then
    echo $theItem
    fi
    But I feel there has to be a better way. I suppose I could put the if in a loop and go through the array, but I'm wondering if there is a route more similar to my basic applescript example.
    Thanks!
    Message was edited by: James Nierodzik because I can't type

    A little follow up: If anyone's using the script I referred to above, I've tweaked the style to override line height and simulate an 80 column display. So the above now looks like:
    <pre style="padding-left: .75ex; padding-top: .25em; padding-bottom: .25em; margin-top: .5em; margin-bottom: .5em; margin-left: 1ex; max-width: 80ex; overflow: auto; font-size: 9px; font-family: Monaco, 'Courier New', Courier, monospace; color: #222; background: #ddd; line-height: normal">#!/bin/sh
    theItem="C"
    if [ $theItem != "A" ] && [ $theItem != "B" ]
    then
    echo $theItem
    fi</pre>
    Cole

  • Using array with a stored procedure

    Hello,
    In order to transmit an array from java to a PL/SQL procedure with oracle8i, we have been trying to instanciate an javaArrayDescriptor using the name of an oracle user Datatype (a table of Varchar(20)).
    This works perfectly well while connected to the database as the owner of the datatype (user 1),
    but doesn't when connected with another user (user 2) even if a public synonym is created.
    As it seemed that synonym for objects do not work properly, we tried to put the datatype as part of a public package.
    This works when the procedure is called from SQL worksheet (connected with user 2) but doesn't when it is called from our java application (still connected with user 2).
    We also created the same datatype for user 2. However the procedure (created by user 1) did not accept the new datatype (error: wrong type or number of arguments) as it requires the user 1 datatype.
    Is there a way to allow any user to use a datatype?
    Or to access a datatype defined in a package fom java in order to make an ArrayDescriptor?

    You should create the TYPE AddrType in Oracle (say thru Sql*Plus) using CREATE TYPE.. command. Currently, looks like you have the TYPE declared within a package.

  • Bug using array in formula node, LV6.0

    Pass a 3-element integer array, containing values 5, 6, 7 into a formula node as input variable x. Pass variable y out. The formula node contains:
    int32 y;
    y = (x[2]-x[1]);
    My result is 6. If the parentheses are removed, the answer is 1. Apparently adding the parentheses causes the expression to be evaluated as y = x[2-1];.
    Has this been found/fixed? I have mailed NI separately.

    In 6.0.2 it returns 1 in both cases.
    "Adam Russell" wrote in message
    news:ajcc8d$1a266r$[email protected]..
    >
    > "Bill Atkins" wrote in message
    > news:[email protected]..
    > > Pass a 3-element integer array, containing values 5, 6, 7 into a
    > > formula node as input variable x. Pass variable y out. The formula
    > > node contains:
    > > int32 y;
    > > y = (x[2]-x[1]);
    > > My result is 6. If the parentheses are removed, the answer is 1.
    > > Apparently adding the parentheses causes the expression to be
    > > evaluated as y = x[2-1];.
    > > Has this been found/fixed? I have mailed NI separately.
    >
    > It works correctly in 6.1. I'm at home so I can't t
    ry it in 6.02.
    >
    >

  • Crash when use indexe array with in place element structure

    Hello !
    I have a problem with in place element structure. I want index a waveform array (16 elements) and when i execute or save that labview close....
    I dont have problem with waveform array 15 elements or less, but i need index 16 elements...
    Thanks for your help !!!
    Solved!
    Go to Solution.
    Attachments:
    Test.PNG ‏8 KB

    I give you my code but it work because i used a waveform array with only 15 elements. I can't save or execute with 16 elements...
    So add it (like picture Test.png) and you will see.
    Thank you
    Attachments:
    Test.vi ‏25 KB

  • Can I use Array Binding with a ExecuteDataSet or ExecuteReader methods?

    I want to use Array binding with selects. From the examples that I see so far it seems like everyone is showing the ExecuteNonQuery method. I wonder if I can use this functionality with a regular query that returns ref cursoros.
    Andrzej

    what is the error you recieve?

  • How use bean of array with tag "jsp:useBean"??

    hi,all
    a bean of array put request with a servlet and forward a jsp page,this jsp use "jsp:useBean" of tag get the bean of array.
    how do for jsp:useBean of tag??
    thx.....

    You can't use an array directly in a jsppage. first u have to write the line <useBean /> through which you can access youtr class
    <jsp:useBean id="email" class="Pack.Email" scope="session" />
    after writing this line you have your class in your hand, you can think of "email" as it is a class object of Email class which is a Bean...
    declare a private array in the Bean and then made method getArray() which will return an array ... then you can use your array in jsp....
    an example of using a class variable in JSp is given below
    public String[] getArray() // note method must be public
    return array;
    now in your jsp page you have to use that class with
    <jsp:useBean id="email" class="Pack.Email" scope="session" />
    and cnow you can use array like this....
    <%
    String[] array=email.getArray();
    for (int i=0; i< array.length;i++ )
    out.println(array]);
    %>
    Does it solve your problem now ?

  • How to auto insert a number array with size of 20 into a named excel file with the positon is from A1 TO A20?i use lv6.1

    can you give me a example vi for it ?thanks a lot!
    how to auto insert a number array with size of 20 into a named excel file  with the positon is from A1 TO A20?i use lv6.1

    You don't need us to give you an example, as the example already comes with LV. Go to Help>>Find Examples and search for "excel". You will find an example called "write table to XL". You should note that the example doesn't do that exactly, because it writes a 2D array from 2 to N.
    You can modify the example by using only one for loop (instead of nested loops) with a 1D array or by going into the Set Cell Value and modifying it to accept a second cell value for the Cell2 terminal and wiring in a 1D array instead of the single string. If you do modify it, be sure to save it under a different name, so you don't overwrite the original.
    To learn more about LabVIEW, I suggest you try searching this site and google for LabVIEW tutorials. Here and here are a couple you can start with. You can also contact your local NI office and join one of their courses.
    In addition, I suggest you read the LabVIEW style guide and the LabVIEW user manual (Help>>Search the LabVIEW Bookshelf).
    Try to take over the world!

  • Using an array with a function

    Hi all,
    I'm working on an order form where users choose a course they want to order from a drop-down list, then enter the number of licences they require. I'm trying to build in a 'volume-based' discount model the form, and would like to ask for some help in using arrays and how to use them in functions. I'm very new to this, and would appreciate any help you can provide!
    Basically, we have 3 products that can be ordered on the same form, and all have different discount models (i.e you get a different % discount for different numbers of licences ordered, depending on the course chosen). I'm storing the discount models in 3 separate two-dimensional arrays, then want to create a function that takes two parameters - the name of the array and the volume that the customer orders - to calculate the appropriate discount. I would then call the function on the change events of either the drop down list or the licence qty field.
    Below is my attempt so far (only one array here, but the others are the same syntax). This is held in a script object called DiscountCalculator in the form. The idea of the function is to loop through the array until it finds the correct course, then loop through the value field until it finds the correct discount:
    //code holds the discount model for each course in a 2 dimensional array. A new array is needed for each course.
    //Course 1
    var
    Course1Array = new Array(3);
    Course1Array[0]
    = new Array(2);Course1Array[0][0]
    = "49";  //'breakpoint' at which discount is appliedCourse1Array[0][1]
    = "0";   //discount % given for this no of licences
    Course1Array[1]
    = new Array(2);Course1Array[1][0]
    = "99";Course1Array[1][1]
    = "20";
    Course1Array[2]
    = new Array(2);Course1Array[2][0]
    = "199";Course1Array[2][1]
    = "25";
    function
    CalculateDiscount(CourseArray, value){
    for
    (var i = 0; i <= CourseArray.length; i++){
    if
    (value <= CourseArray[i][0]){
    return CourseArray[i][1]}
    I can use a MessageBox to return a specified value from the array on the click event, so that seems to be set up correctly. But when I try to tcall the function in the change event of the drop-down list on the form:
    DiscountCalculator.CalculateDiscount(fldCourse.rawvalue, fldqty.rawvalue)
    It doesn't work, usually complaining that "Course1Array is not defined". I think it must be some kind of syntax error, but I have trawled the internet looking for some examples and can't find any.
    I'd be grateful for any assistance.
    Thanks
    Matt

    It might be easy to solve these issues if you post your form.
    Post your form if it doesn't contain any confidential information.
    Nith

  • How to use array function?

    I want to create a array with the data are in the table (one or more than one field).
    By using function makearray or array, it can create the array with one record
    e.g.
    Local  stringvar Array x := MakeArray ({CASES.ASSIGNTO});
    ubound(x);
    the result will be 1, means only one record is in the Array x.
    Actually, I want to get all records of the field CASES.ASSIGNTO.

    Hello Kent,
    You can't just assign all field values to an array, the formula needs to process each record in the details section and assign the record to the array. Here is a sample formula that would assign all countries to an array;
    WhilePrintingRecords;
    stringvar array t;
    numbervar x;
    x:= x + 1;
    redim preserve t[x];
    t[x]:= {Customer.Country};
    t[x]
    If you need the completed array available in the main report before the Report Footer then you would need to use a subreport in the Report Header to generate the array and then using a shared variable pass it back to the main report.
    Also note that an array is limited to 1000 elements so if there is a possibility of the number of records exceeding 1000 you will need to create more than 1 array and depending on the value of the counter assign the records greater than 1000 to the second array

  • BW 3.5 - Issue with formula variable with replacement path

    Dear experts,
    I'm facing an issue with formula variable with replacement path.
    Just to clarify, I know replacement paths is raising a lot of questions but I've been using this functionnality extensively in the past, both in 7.0 and 3.5, so I'm not looking for basic information about how to use it.
    I'm trying to setup a simple report that would show total values per plant of Purchase Order < 100 €
    To do so I've setup a calculated key figure as follow:
    VAR1 * ("PO value" < 100 ) * "PO value"
    VAR1 is a formula variable with replacement path on 'purchase order' and value attribute 'constant =1'.
    (The report has to show values summarized by plant but should not show the detail PO by PO, so I'm not looking at a solution based on condition)
    The report as characteristic "plant" in rows and my CKF in columns.
    Now let's take an example. I have 3 POs in Plant 1:
    PO1 -> 150€
    PO2 -> 90€
    PO3 -> 80€
    Because of the variable with replacement path, the result in my query should be:
    plant1 = 170 (even though characteristic "purchase order" is not in my rows, system should evaluate PO one by one and return values only for those two that are below 100).
    But the result coming is 320, which is wrong.
    I've done the same report on many other 3.5 systems and it worked perfectly, and I am not able to get proper support from SAP OSS who keep saying that this functionnality is not ready in 3.5 (although I've provided screenshot of this working on another 3.5 system!!! how frustrating...)
    They have also pointed to problems of Before and After aggregation but that has absolutely no impact. Once again, the scenario is working perfectly on other 3.5 systems with the same query design, so i'm sure it has nothing to do with Query Designer options.
    Would anyone have ever come to an equivalenet problem? I'm wondering whether the DB itself could not play a role in the variable with ref  characteristic 'constant =1' ...
    Any though is welcome!
    thanks

    Hi,
    The text variable is replaced when the exact date is clear for this key figure column according to the restriction.
    To achive this, please make sure that either the variable is directly restricted in the key figure selection, or that the date characteristic is in drilldown.
    Regards,
    Patricia

  • How do I create an array with variables also splits words  in a txtfile?

    Hello guys,
    I made a script that reads a text file.
    function readMyFile()
    var myFile=File(app.activeDocument.filePath + "/LareLog.txt");
    if (myFile.exists)
            myFile.open("r");
            var Temps =  myFile.read();
            alert (Temps);                          // message the content
            var nyRad=("\n");                    // break the line
            textArr=Temps.split(nyRad);
            alert(textArr);                          // message the content with all info on new lines ("\n");
            myFile.close();
    my textfile contains:
    ~/Desktop/3.indd ,Thu Mar 20, 2014, 11:26:34 , GMT+0100
    I wonder how do I sort the content in array
    in this order, also creates variables for each string.
    var= string 1[~/Desktop/3.indd]
    var2=string 2[11:26:34]
    var3=string 3[11:26:34]
    var4=string 4[2014]
    var5=string 5 [GMT+0100]
    Thank you in advance people.

    Hmmh?
    Jump_Over said it before: „… are stored as separate array's elements …“ in your [textArr]
    So you can create now variables on this way:
    var string_1 = textArr[0]; // and so on
    alert(string_1);
    See Java Scripting reference for more examples how to use Arrays.

  • Issue with formula collision

    Hello Experts,
    I am facing an issue with Formula collision, below is an expample
    My requirement is to use Column formula for the value (????) in the below table.
                                  Restriction (C1)     Restriction (C2)     Formula(C1-C2)
    Restriction (R1)     4              2                                 2
    Restriction (R2)     8              3                                 5
    Formula(R1+R2)     12              5                              ????
    I have tried using the below settings
    1) Formula(R1+R2)  "Standard"
    2) Formula(C1-C2)  " Use result of this formula"
    But still getting row formula being used, please advice.
    Thanks,

    Select the Formula which you created Formula(C1-C2)
    In the properties tab Go to Calculations--> Select the Check Box Cumulated
    In the Drop Down for Calculation Direction Select --> Calculate Along Columns
    If you require you can also select the Check Box Also Apply to Results
    Hope it Helps.
    rgds, Ghuru

  • How to use TAXBRJ with TAXBRA activated at core level for Brazil

    Hi Experts,
    I am supporting Brazil localization  customization in ECC 6.0 for our company. We activated TAXBRA for Brazil. We flagged off CBT for all SD pricing procedure knowing the value of RVABRA. But one process in brazil we presently using in 4.6C with TAXBRJ along with customized pricing procdure make use of formula based calculation.
    So we would like to follow the same method in ECC 6.0 also. However the condition based calculation RVABRA does not support this process as this process requires more formula based calculation.
    So we need to know is there any chance to use TAXBRJ with customized formula based SD price procedure for our requirement.
    I read through document (Condition based calculation in R/3 for Brazil version 3.1) the following steps to do alternate calculation procedure:
    "In R/3 Enterprise, an extension to the concept described in section 5.8 has been introduced. In the table J_1BMWSKZKALSM,
    alternative calculation procedures can be specified that are to be used for certain tax codes instead of the standard one. This is achieved by reading this table in a BAdI before the call to the pricing procedure and modifying the communication fields that contain the calculation procedure and the tax code.
    Thus the user could e.g. use the external tax calculation for some tax codes (by specifying TAXBRJ in the above mentioned table) or use several smaller calculation procedures, e.g. in case of performance problems or new requirements."
    We also would like to know what is the Badi mentioned in this document
    to acheive this ?
    Thanks
    Rajesh babu

    Do it as mentioned below:
    <?if:count(RECORD_TYPE)>0?>
    <?split-by-page-break:?>
    <?end if?>
    Copyright Statement
    Customer Disclaimer Notice
    The information contained in the First Databank(FDB)databases is intended to supplement the
    knowledge of physicians, pharmacists and other healthcare professional regarding drug therapy problems and patient counseling information. This information is advisory only and is not intended to replace sound clinical judgment in the delivery of healthcare services.
    FDB disclaims all warranties, whether expressed or implied, including any warranty as to the quality, accuracy and suitability of this information for any purpose.
    FOR IFRECORD_VALUEENDIFERER
    Call your doctor for medical advice about your side effects. You may report Side Effect to FDA at 1-800 FDA-1088
    Ask your Pharmacist for more information about this drug. You have the right to counseling from our Pharmacists. If you have any questions about this medication, please call the pharmacy
    By signing below, I acknowledge receipt of this document and my informed consent to accept this medication.
    Sig _________________________________________________
    Thanks - Bhanu

  • Problem in using array variable in PartnerLinks

    I have a stored procedure in Oracle DB,which the parameters is a varray with types,such as
    type temp1 as object (temp_id varchar(10),temp_desc varchar(512));
    TYPE templist AS VARRAY(50) OF TEMP1
    procedure testArray1(accounting_temps IN templist)
    I used the database adapter to generate a partnerlink,it can work,but when I assign the variables to DBAda1_InputVariable (using while to read all data in xml),it only send a array with one value,the last value updates the value before.
    How to add the array (not update) variable in this case??
    Thanks and best regards!!

    I have a stored procedure in Oracle DB,which the parameters is a varray with types,such as
    type temp1 as object (temp_id varchar(10),temp_desc varchar(512));
    TYPE templist AS VARRAY(50) OF TEMP1
    procedure testArray1(accounting_temps IN templist)
    I used the database adapter to generate a partnerlink,it can work,but when I assign the variables to DBAda1_InputVariable (using while to read all data in xml),it only send a array with one value,the last value updates the value before.
    How to add the array (not update) variable in this case??
    Thanks and best regards!!

Maybe you are looking for

  • High pitch noise in CS4 and CS5.5

    Hello. Firstly I want to say that yes I know people have asked this question before but as far as I can tell none of them have been solved. Some have somewhat useful answers but none of them truely solve the problem. This thread in particular probabl

  • Content Conversion not creating a new line....

    I have areceiver FCC configured in my scenario but the problem is that output file is producing content which comes over one line... As in there is no new line for each substructure. This is a new problem as last month when we tested the scenario wor

  • Error -6636 when create a TDMS file

    I use the following function to create a TDMS file. I got the error information. What is the problem? I did add the tdms extension name. TDMS_CreateFileEx ("filePath", TDMS_Streaming2_0, TDMS_ByteOrderLittleEndian, 0, "DAQ Test", "My TDMS Test execis

  • Systemd-206 revives old bug? seq/timer permission

    After upgrading to systemd 206 /dev/snd/seq and /dev/snd/timer have permission 0600. Found this: https://bugs.archlinux.org/task/24362 This was fine in 204. EDIT: I'm not running a display manager but rather starting XBMC through a service. The user

  • Quickest & Easiest Way To Create & Publish website using Illustrator Designs?

    HI there I am a newbie & more conversant in premier pro than webiste development, however I though I would give it a go. I have watched that many Lynda.com video's I think I have confused myself! I have created all of the pages I need for my website