Math.pow--找不到符号?

时间:2014-09-29 23:48:59

标签: java

我在尝试计算程序中创建的每月抵押金额时遇到了java编程类分配问题。一旦尝试编译代码,我收到错误'找不到符号 - 方法inter(double)' 计算月利率的公式是 -

我目前认为在switch语句之外看不到double值,但我不太确定这里的问题是什么。 ._。;

感谢您的帮助!

我的代码:

import java.util.*;


public class MorgageCalculator
{
 public static void main(String[]args)
  {
       Scanner s = new Scanner(System.in);
        double principal = 0;//principle amount
        int period =0;//number of years required to pay out mortgage
        double inter =0; //interest rate
        int amr =0;//monthly payments
        char another ='y';
        double monthly=0;
        String input;
        System.out.println("Enter principle amount, value cannot be negative");
        principal=s.nextDouble();
       while(principal <=0){


            while(inter==0){
                System.out.println("Enter mortage term: (1,2,3,5,10)");
                period=s.nextInt();
            switch(period){
                case 1: 
                inter=3.5;
                break;
                case 2: 
                inter=3.9;
                break;
                case 3: 
                inter=4.4;
                break;
                case 5: 
                inter=5.0;
                break;
                case 10: 
                inter=6.0;
                break;
                default:
                inter=0;

            } 
            if(inter==0){System.out.printf("%f is not a valid period, please enter a new one \n",period);
            }
        }
                System.out.printf("The inter rate for the term will be %.2f \n",inter);
          while(amr==0){
                System.out.println("Enter morgage amortization period (5,10,15,20,25)");
            amr=s.nextInt();
                switch(amr){
                    case 5:
                    amr= 5*12;
                    break;
                    case 10: 
                    amr= 10*12;
                    break;
                    case 15:
                    amr= 15*12;
                    break;
                    case 20:
                    amr= 20*12;
                    break;
                    case 25:
                    amr= 25*12;
                    break;
                    default:
                    amr= 0;
                }
               if(amr==0){
                   System.out.printf("%f is not a valid amortization period, please enter a new one.");
                }
            }
inter=inter/100;
monthly=(principal(Math.pow(inter(1+inter),amr))/(Math.pow(1+inter,amr)-1));

                  }

    }

  }

2 个答案:

答案 0 :(得分:1)

在最后一行(您指定给monthly的地方),您缺少一个乘法运算符。将inter(1 + inter)替换为inter*(1 + inter)

答案 1 :(得分:0)

inter是变量而不是方法。在这一行中,您试图将其用作方法:

        monthly = (principal(Math.pow(inter(1 + inter), amr)) / (Math.pow(
                1 + inter, amr) - 1));