I keep getting an error that symbol ( *, /, – depending on the line) cannot be applied to a double[] or int[].?

import static java.lang.Math.*;
import java.util.*;
import java.io.*;
import java.text.*;

public class mortgageCalculator3 {

public static void main(String[] args) throws IOException{

NumberFormat currency=NumberFormat.getCurrencyInstance();

System.out.println("Juanita Smith");

System.out.println("Week 4 Assignment");

System.out.println("Mortgage Calculator");

System.out.println("August 29, 2011");

pauseProg(); // code to pause program found at
//http://codewithdesign.com/2010/01/17/create-a-press-enter-to-continue-with-java/
}

public static void pauseProg() throws IOException{
System.out.println("Press enter to continue…");
Scanner keyboard = new Scanner(System.in);
keyboard.nextLine();

//Calculate the monthly mortgage payment for a 20,000 loan
//with 5.35 percent interest over seven years…
//and 5.5 percent interest over 15 years…
//and 5.75 percent interest over thirty years.

// define the array of interest rates for all necessary terms
double [] APR = {0.0535, 0.055, 0.0575};

//define array of note period for all necessary terms
int [] NP= {84, 180, 360};

//define array of terms for output
int [] Terms= {7,15,30};

//interest rate per month
double IR= (double) (APR/12);

//principle Value
int PV= 200000;

//monthly payment with interest
double PMT= (200000 * IR)/(1-Math.pow(1+IR,-NP));

//monthly payment without interest
double MPMT = 200000/360;

//Loan total with interest
double BT =(PMT*360);

///the actual number of payments
int NPMT = 0;

//actual amount paid
double PMTD= (PMT * NPMT);

//loan balance after given number of payments has been made
double Balance= (BT-PMTD);

//Interest paid so far for each payment
double IRT= (IR * NPMT);

//number of payments in the Mortgage in Years
int NPY = 30;

//monthly payment without interest
double PMTI= PMT-IR;

//input more necessary tools

NumberFormat currency=NumberFormat.getCurrencyInstance(); //allows currency format

InputStreamReader isr = new InputStreamReader(System.in); //alls reading strings

BufferedReader bfr = new BufferedReader(isr);// allows another pause in the program

//for loop to calcullate and display the terms
for (int i=0;i<NP.length;i++){

System.out.println("Monthly Payment on a 0,000 loan over" + Terms +"years");
System.out.println("at " + APR*100 + "% interest is");
System.out.println(currency.format(PMT));

System.out.println();

}

}
}
The PMT calculation it says – cannot be applied in the -NP
The IR calculation it says / cannot be applied in the APR/12
The System.out.println it says * cannot be applies in the APR*100

These are the only errors I am getting right now. Yes, this is in Java ( I ran out of characters for the question). I would really like to know what I am doing wrong so I can finish this. Please! Thank You!

4 Responses to I keep getting an error that symbol ( *, /, – depending on the line) cannot be applied to a double[] or int[].?

  1. CP

    After a quick look at it, I think the problem is you are not specifying the element of the array, so you are telling it to try to do math on the whole array.

    For example:
    double IR= (double) (APR/12);

    should be:
    double IR= (double) (APR[0]/12)

    This references element 0 of APR which you defined as 0.0535.

  2. Don't sue me!

    I’m not sure about this since I don’t know Java.
    You can’t multiply or divide arrays, you need to specify an index to retrieve the int or double from the array and then do these operations.

    EG:
    double IR= (double) (APR/12); // wrong
    double IR= (double) (APR[0]/12); // correct

  3. Rick Mills

    APR, NP and Terms are all arrays.

    In your code example above, you have a "for" loop,

    for (int i = 0; i < NP.length; i++)

    but within that "for" loop, you then have a System.out where you say:

    System.out.println("at " + APR * 100 + "% interest is");

    But APR is an array of doubles – so what you need to do is to change the code to say:

    System.out.println("at " + APR[i] * 100 + "% interest is");

    instead – so you are reading the APR for index i in the array – which I think should do what you want.

  4. Dark Satan

    The problem in your code is at-
    //interest rate per month
    double IR= (double) (APR/12);

    You can’t perform arithmetic operations on arrays, but you can with their values –
    double IR= (double) (APR[i]/12); OR double IR= (double) (APR[0]/12);
    Here APR[0] refers to the first value of the array ie. 0.0535

    And the same mistake is repeated at-
    //interest rate per month
    double IR= (double) (APR/12);

    double PMT= (200000 * IR)/(1-Math.pow(1+IR,-NP));

    System.out.println("at " + APR*100 + "% interest is"); & so on & so forth

Leave a Reply