zoukankan      html  css  js  c++  java
  • 复利计算5.0(改成Java版本)与 单元测试

    //由于C语言版本不方便单元测试,所以改成了java版本,部分代码如下:
    import
    java.util.Scanner; public class FuLi{ public static void main(String[] args) { Scanner scanner=new Scanner(System.in); System.out.println(" 复利计算按 1 单利计算按 2 计算筹集的养老金按 3 计算时间按 4 计算您要的利率按 5 计算本利和投资按 6 计算等额本息还款按 7 "); int C=scanner.nextInt(); if(C==1){ System.out.println("输入您的本金:"); double money = new Scanner(System.in).nextDouble(); System.out.println("输入您期望的年利率:"); double rate = new Scanner(System.in).nextDouble(); System.out.println("输入您期望的存入期(年)数:"); int year = new Scanner(System.in).nextInt(); double result=money*(1+rate*year); System.out.println("计算结果为:"+result); } if(C==2){ System.out.println("输入您需要筹得的金额:"); double futuremoney = new Scanner(System.in).nextDouble(); System.out.println("输入您期望的存入期(年)数:"); int year = new Scanner(System.in).nextInt(); System.out.println("输入您期望的利率:"); double rate = new Scanner(System.in).nextDouble(); double result = futuremoney/(1+rate*year); System.out.println("您需要存的本金是:"+result); } } }

     我也进行了这两个功能的单元测试。首先是复利计算的测试。运行结果和测试结果如下:

    然后是第二个测试,是关于筹集养老金的,运行结果和测试结果如下:

  • 相关阅读:
    poj 1698 二分图多重匹配
    poj 3207 2-sat
    hdu4932 Miaomiao's Geometry
    hdu4924 Football Manager
    hdu4914 Linear recursive sequence
    hdoj4906 Our happy ending(2014 Multi-University Training Contest 4)
    poj1987 Distance Statistics
    poj3342 Party at Hali-Bula
    C/C++ 调用qsort/sort 对字符数组排序的cmp函数写法
    poj1947 Rebuilding Roads
  • 原文地址:https://www.cnblogs.com/lieson/p/5335203.html
Copyright © 2011-2022 走看看