日期:2014-05-20 浏览次数:20758 次
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;
}}
public carloan(double price,double downpayment)学Java怎么会不知道构造方法呢?建议找本书看看,这是Java最基础的东西!
{
this.price = price;
this.downpayment = downpayment;
}