⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loan.java

📁 还不错的java基本实例
💻 JAVA
字号:

/**
 * Created by IntelliJ IDEA.
 * User: shaohj
 * Date: 2005-8-30
 * Time: 17:48:13
 * To change this template use File | Settings | File Templates.
 */
public class Loan {
    private  final int  MONTHS_IN_YEARS=12; //声明字段常量
    private double loanAmount; //声明字段 loanAmount
     //  private int years;//声明字段 years
     private int months;//声明字段months
       private float annualInterestRate;//声明字段  annualInterestRate

      //声明读取属性LoanAmount的值方法
      public double getLoanAmount(){
          return loanAmount;
      }
      //声明设置属性LoanAmount的值的方法
      public void setLoanAmount(double newloanAmount){
          if(newloanAmount>0)
             loanAmount=newloanAmount;
          else
              loanAmount=0;         
      }

       //声明设置属性Years的值的方法
      public void setYears(int newyear){
           if(newyear>0)
           {
          //  years=newyear;
            months = newyear * MONTHS_IN_YEARS; }
            else
           {
           // years=0;
            months = 0;
           }
      }
       //声明读取属性Years的值的方法
      public int getYears(){
        //  return years;

          return (int)months/  12.0;
      }

    //声明读取属性Months的值的方法
      public int getMonths(){
          return months;
      }
    //声明设置属性Months的值的方法
     public void setMonths(int newmonth){
        if (newmonth>0)
           // years=(int)newmonths/12.0;
           months = newmonth;
        else
             months =0;
      }

         //声明读取属性AnnualInterestRate的值的方法
       public float getAnnualInterestRate(){
          return annualInterestRate;
      }
       //声明设置属性AnnualInterestRate的值的方法
       public void setAnnualInterestRate(float newAnnualInterestRate){
          annualInterestRate=newAnnualInterestRate;
      }

      //声明计算月付款的方法
       public double computeMonthlyPayment(){
           float  monthlyInterestRate;
  int numberOfPayments ;
           double monthlyPayment ;
           monthlyInterestRate = annualInterestRate / 100.0f /  MONTHS_IN_YEARS;
            numberOfPayments = getMonths();
            monthlyPayment = (loanAmount * monthlyInterestRate) /
                    (1 - (Math.pow((1 + monthlyInterestRate), -numberOfPayments)));
           return monthlyPayment;
       }

      //声明计算总付款的方法
       public double computeTotalPayment(){
           double totalPayment ;
           totalPayment = computeMonthlyPayment()*getMonths();
           return totalPayment;
       }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -