• 0709--第六章2题


    模拟一个简单的购房商贷月供计算器

    月供计算代码:

    /**
     * @author Mr.Wang
     * 获取金额以及年限,计算月供
     *
     */
    public class BuyHouse {
        public double counts(double money,int years) {
            double counts = 0;
            switch (years) {
            case 3:
                counts = (money + money*0.0603)/36;
                break;
            case 5:
                counts = (money + money*0.0612)/60;
                break;
            case 20:
                counts = (money + money*0.0639)/240;
                break;
    
            default:
                break;
            }
            
            return counts;
            
        }
    }

    用户操作界面代码:

    import java.util.Scanner;
    
    /**
     * @author Mr.Wang
     * 用户操作界面,获取输入的贷款金额以及客户选择年限
     *
     */
    public class Uer {
        Scanner input = new Scanner(System.in);
        BuyHouse bh = new BuyHouse();
        int years;
        double money;
        double counts;
        public void option() {
            System.out.print("请输入贷款金额:");
            money = input.nextDouble();
            System.out.println("请选择贷款年限:1.3年(36个月)    2.5年(60个月)    3.20年(240个月)");
            int i = input.nextInt();
            switch (i) {
            case 1:
                years = 3;
                counts = bh.counts(money, years);
                System.out.println("3年(36个月)月供为:"+counts);
                break;
            case 2:
                years = 5;
                counts = bh.counts(money, years);
                System.out.println("5年(60个月)月供为:"+counts);
                break;
            case 3:
                years = 20;
                counts = bh.counts(money, years);
                System.out.println("20年(240个月)月供为:"+counts);
                break;
    
            default:
                System.out.println("谢谢使用本系统!");
                break;
            }
            System.out.println("");
        }
    }

    测试代码:

    /**
     * @author Mr.Wang
     * 模拟一个简单的购房商贷月供计算器
     *
     */
    public class Text {
        public static void main(String[] args) {
            Uer uer = new Uer();
            uer.option();
        }
    }

    运行结果测试:

  • 相关阅读:
    .NET Framework Execution Was Aborted By Escalation Policy
    语句获取作业属性、历史记录
    Login failed知多少
    数据库代理错误日志
    微信小程序资料
    时间进度条,根据时间,显示任务进度条
    两个select 左右添加,上下移动
    图片轮播无缝接
    CSS3简单的栅格系统
    JavaScript DOM节点和文档类型
  • 原文地址:https://www.cnblogs.com/Dean-0/p/11164017.html
Copyright © 2020-2023  润新知