/*模拟一个简单的购房商贷月供计算器,按照以下公式计算总利息和每个月还款金额: 总利息=贷款金额*利率; 每月还款金额=(贷款金额+总利息)/贷款年限

package homeWork;

public class HousePurchas {

    //计算总利息
    public double totalInterest(int num,int year){
        double total = 0;

        if(year==3){

            total = num*0.0603;

        }
        if (year == 5){

            total = num*0.0612;

        }
        if (year == 20){

            total = num*0.0639;
        }

        return total;
    }

    //计算每月还款金额

    public double repay(int num,double total,int year){

            double repays = (num+total)/(year*12);
            return repays;

    }

}
package homeWork;

public class House {

     private double toalinterest; //总利息
     private int year;//贷款年份
     private int summoney;//贷款总金额
     private double nummonth;//每月还款金额


    //定义无参变量
    public House() {
    }


    public House(double toalinterest, int year, int summoney, int nummonth) {
        this.toalinterest = toalinterest;
        this.year = year;
        this.summoney = summoney;
        this.nummonth = nummonth;
    }

    //定义有参变量


    //封装为set,get

    public double getToalinterest() {
        return toalinterest;
    }

    public void setToalinterest(double toalinterest) {
        this.toalinterest = toalinterest;
    }

    public int getYear(int b) {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public int getSummoney(int a) {
        return summoney;
    }

    public double getNum() {
        return nummonth;
    }

    public void setNum(int num) {
        this.nummonth = nummonth;
    }

    public void setSummoney(int summoney) {
        this.summoney = summoney;

    }
    //计算总利息
    public void calint(){


        if (this.year==3){

            this.toalinterest = this.summoney*0.0603;
        }
        if (this.year==5){
            this.toalinterest = this.summoney*0.0612;
        }
        if (this.year==20){
            this.toalinterest = this.summoney*0.0639;
        }

    }

    //计算每月还款金额
    public void repamo(){

        this.nummonth=(this.toalinterest+this.summoney)/(this.year*12);

    }

    //打印方法
    public  void disply(){
        System.out.println("***月供为:"+this.nummonth);
    }

}
package homeWork;

import java.util.Scanner;

public class HouseTest {
    public static void main(String[] args) {
        System.out.println("输入贷款金额:");
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        System.out.println("请选择贷款年限:1.3年(3年(36个月)   2.5年(60个月)      3.20年(240个月)      ");
        int b =scanner.nextInt();

        House house =new House();
        house.setSummoney(a);
        house.setYear(b);
        house.calint();
        house.repamo();
        house.disply();
    }

}

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值