zoukankan      html  css  js  c++  java
  • 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();
        }
    }

    运行结果测试:

  • 相关阅读:
    【svn】一个设置,少写几个字
    转眼一年
    linux虚拟机与windows主机传输文件方法
    meta常用命令
    Metasploit 读书笔记-持久控制
    Metasploit 读书笔记-神器Meterpreter
    [工作]采购失误
    解决:kali linux 在vmware 虚拟机中使用bridge模式上网的问题
    metasploit 读书笔记-EXPLOITATION
    [共鸣]温州600住户合买高音炮 还击广场舞大妈
  • 原文地址:https://www.cnblogs.com/Dean-0/p/11164017.html
Copyright © 2011-2022 走看看