显示所有线性元素

显示所有线性元素

分三部分

代码如下:

一部分

package Day05;

public class Circle {

private double radius = 1.0;

final static double pi = 3.1415926;

/**
* @param radius
*/
public Circle(double radius) {
this.radius = radius;
}
/**
*
*/
public Circle() {
this(10.0);
}



public double getRadius() {
return this.radius;
}
public void setRadius(double radius) {
this.radius = radius;
}

double getArea() {
return radius * radius * Math.PI;
}

public static String getName() {
return "Circle";
}

@Override
public String toString() {
return "Circle [radius=" + radius + "]";
}

}

二部分

package Day06;
import java.util.Date;

public class Loan {
//年利率
private double annualInterestRate;
//贷款年限
private int numberOfYears;
//贷款总额
private double loanAmount;
//贷款生成时间
private Date loanDate;


/**
*
*/
public Loan() {
this(0, 1, 1, new Date());
}

/**
* @param annualInterestRate
* @param numberOfYears
* @param loanAmount
*/
public Loan(double annualInterestRate, int numberOfYears, double loanAmount) {
this.annualInterestRate = annualInterestRate;
this.numberOfYears = numberOfYears;
this.loanAmount = loanAmount;
this.loanDate = new Date();
}


/**
* @param annualInterestRate
* @param numberOfYears
* @param loanAmount
* @param loanDate
*/
public Loan(double annualInterestRate, int numberOfYears,
double loanAmount, Date loanDate) {
this.annualInterestRate = annualInterestRate;
this.numberOfYears = numberOfYears;
this.loanAmount = loanAmount;
this.loanDate = loanDate;
}

/**
* @return the annualInterestRate
*/
public double getAnnualInterestRate() {
return annualInterestRate;
}

/**
* @param annualInterestRate the annualInterestRate to set
*/
public void setAnnualInterestRate(double annualInterestRate) {
this.annualInterestRate = annualInterestRate;
}

/**
* @return the numberOfYears
*/
public int getNumberOfYears() {
return numberOfYears;
}

/**
* @param numberOfYears the numberOfYears to set
*/
public void setNumberOfYears(int numberOfYears) {
this.numberOfYears = numberOfYears;
}

/**
* @return the loanAmount
*/
public double getLoanAmount() {
return loanAmount;
}

/**
* @param loanAmount the loanAmount to set
*/
public void setLoanAmount(double loanAmount) {
this.loanAmount = loanAmount;
}

/**
* @return the loanDate
*/
public Date getLoanDate() {
return loanDate;
}

/**
* @param loanDate the loanDate to set
*/
public void setLoanDate(Date loanDate) {
this.loanDate = loanDate;
}

/**
* 计算月还款数额
*/
public double getMonthlyPayment() {
double monthlyInterestRate = this.annualInterestRate / 1200;
double monthPayment =
this.loanAmount * monthlyInterestRate
/ (1 - 1 / Math.pow(1 + monthlyInterestRate, this.numberOfYears * 12));
return monthPayment;
}

/**
* 计算还款总金额
*/
public double getTotalPayment() {
return this.getMonthlyPayment() * this.numberOfYears * 12;
}

/**
* 计算贷款结清时间
*/
@SuppressWarnings("deprecation")
public Date getLoanPaidDate() {
Date loanDay = this.loanDate;
loanDay.setYear(loanDay.getYear() + this.numberOfYears);
return loanDay;
}

@Override
public String toString() {
return "Loan [annualInterestRate=" + annualInterestRate
+ ", numberOfYears=" + numberOfYears + ", loanAmount="
+ loanAmount + ", loanDate=" + loanDate + "]";
}

}

三部分

package Day07;

import java.util.ArrayList;
import java.util.Date;

import Day05.Circle;
import Day06.Loan;

public class Homework02 {
public static void main(String[] args) {
ArrayList arr = new ArrayList();
arr.add(new Loan());
arr.add(new Date());
arr.add("avb");
arr.add(new Circle());
for (int i = 0; i < arr.size(); i++) {
System.out.println(arr.get(i).toString());
}
}
}

posted @ 2017-06-20 19:24  辰峰  阅读(240)  评论(0编辑  收藏  举报