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

📄 exercise15_4.java

📁 java程序设计导论(daniel liang著) 所有偶数课后习题答案
💻 JAVA
字号:
public class Exercise15_4 {  public static void main(String[] args) {    try {      new NewLoan(7.5, 30, 100000);      NewLoan m = new NewLoan(-1, 3, 3);      new NewLoan(7.5, 30, 20000);    }    catch (Exception ex) {      System.out.println(ex);    }        System.out.println("End of program");  }}class NewLoan {  private double annualInterestRate;  private int numOfYears;  private double loanAmount;  /** Default constructor */  public NewLoan() {    this(7.5, 30, 100000);  }  /** Construct a NewLoan with specified annual interest rate,      number of years and loan amount    */  public NewLoan(double annualInterestRate, int numOfYears,    double loanAmount) {        if (annualInterestRate <= 0)      throw new IllegalArgumentException("Annual interest rate must be positive.");    if (numOfYears <= 0)      throw new IllegalArgumentException("Number of years must be positive.");    if (loanAmount <= 0)      throw new IllegalArgumentException("Loan amount must be positive.");    setAnnualInterestRate(annualInterestRate);    setNumOfYears(numOfYears);    setLoanAmount(loanAmount);  }  /** Return annualInterestRate */  public double getAnnualInterestRate() {    return annualInterestRate;  }  /** Set a new annualInterestRate */  public void setAnnualInterestRate(double annualInterestRate) {    if (annualInterestRate <= 0)      throw new IllegalArgumentException("Annual interest rate must be positive.");    this.annualInterestRate = annualInterestRate;  }  /** Return numOfYears */  public int getNumOfYears() {    return numOfYears;  }  /** Set a new numOfYears */  public void setNumOfYears(int numOfYears) {    if (numOfYears <= 0)      throw new IllegalArgumentException("Number of years must be positive.");    this.numOfYears = numOfYears;  }  /** Return loanAmount */  public double getLoanAmount() {    return loanAmount;  }  /** Set a newloanAmount */  public void setLoanAmount(double loanAmount) {    if (loanAmount <= 0)      throw new IllegalArgumentException("Loan amount must be positive.");    this.loanAmount = loanAmount;  }  /** Find monthly payment */  public double monthlyPayment() {    double monthlyInterestRate = annualInterestRate / 1200;    return loanAmount * monthlyInterestRate / (1 -       (Math.pow(1 / (1 + monthlyInterestRate), numOfYears * 12)));  }  /** Find total payment */  public double totalPayment() {    return monthlyPayment() * numOfYears * 12;  }}

⌨️ 快捷键说明

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