• 显示所有线性元素


    显示所有线性元素

    分三部分

    代码如下:

    一部分

    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());
    }
    }
    }

    只相信苦尽甘来
  • 相关阅读:
    c#——总结两种方式下载模板
    c#——NPOL下载
    c#——泛型类型约束
    Oracle 数据类型
    软件测试绩效评估点
    读《没有带不好的员工》总结
    安装jenkins,配置pipline 运行docker
    K8S pv与pvc匹配不到的坑
    jenkins 在pipeline中运行docker镜像执行测试代码
    k8s 储存卷的定义与使用
  • 原文地址:https://www.cnblogs.com/F001li/p/7055902.html
Copyright © 2020-2023  润新知