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

    运行结果测试:

  • 相关阅读:
    CSU 1333 Funny Car Racing
    FZU 2195 检查站点
    FZU 2193 So Hard
    ZOJ 1655 FZU 1125 Transport Goods
    zoj 2750 Idiomatic Phrases Game
    hdu 1874 畅通工程续
    hdu 2489 Minimal Ratio Tree
    hdu 3398 String
    洛谷 P2158 [SDOI2008]仪仗队 解题报告
    POJ 1958 Strange Towers of Hanoi 解题报告
  • 原文地址:https://www.cnblogs.com/Dean-0/p/11164017.html
Copyright © 2011-2022 走看看