• 复利计算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); } } }

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

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

  • 相关阅读:
    线程的同步之Synchronized的使用
    线程的优先级
    线程的状态和常用操作
    Eclipse设置代码模板Code Template
    Eclipse设置每行代码的长度
    Eclipse设置控制台字体
    Gradle 安装(Windows)
    DSL与GPL
    Windows 新增 Sublime Text3 右键快捷方式
    mvn install 上传 jar 包到Maven仓库
  • 原文地址:https://www.cnblogs.com/lieson/p/5335203.html
Copyright © 2020-2023  润新知