栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

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

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

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

}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1013301.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号