日期:2014-05-20  浏览次数:20711 次

求各位大神指条明路
car.java:33: error: constructor carloan in class carloan cannot be applied to given types;
carloan vn= new carloan(price, downpayment);
            ^
  required: no arguments
  found: double,double
  reason: actual and formal argument lists differ in length
1 error

这个是我的error.

import java.util.Scanner;

public class car{
public static void main(String[] args){
double price;
double downpayment;
double interest;
int months;
int payment;

Scanner in= new Scanner(System.in);

System.out.print("Please enter the car price: ");
price=in.nextDouble();
System.out.println();

System.out.print("Please enter the amount of downpayment: ");
downpayment=in.nextDouble();
System.out.println();

System.out.print("Please enter the annual interest rate: ");
interest=in.nextDouble();
System.out.println();

System.out.print("Please enter the loan period in months: ");
months=in.nextInt();
System.out.println();

System.out.print("Please enter the number of payments you have paid: ");
payment=in.nextInt();
System.out.println();

carloan vn= new carloan(price, downpayment);

System.out.print("The amount borrowed is: "+ vn.getamountborrowed());
System.out.print("The monthly payment amount is: "+ vn.getmonthlyrate());
}}



public class carloan{
private double price;
private double downpayment;
private double interest;
private int months;

public double getamountborrowed(){
return price-downpayment;
}

public double getmonthlyrate(){
double P=price-downpayment;
double R=interest/12;
double B=1+R;
double C= Math.pow(B,months);
double D=R*C;
double E=C-1;
double F=D/E*P;
return price;
}}




我想知道为什么会出现这样的error.
------解决方案--------------------
构造方法可以理解为是为了初始化数据,就是这样:
public carloan(double price,double downpayment)
{
this.price = price;
this.downpayment = downpayment;
}
学Java怎么会不知道构造方法呢?建议找本书看看,这是Java最基础的东西!