博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
0330 复利程序c语言版转java版 会逐渐更进版
阅读量:5022 次
发布时间:2019-06-12

本文共 7938 字,大约阅读时间需要 26 分钟。

import java.util.Scanner;public class compounding {    public static void main(String[] args) {        menu();        int m = scanner.nextInt();        switch(m)        {        case 1:            compound_calate(); break;        case 2:            single_calate();break;        }              }    private static void compound_calate() {
//复利计算 while (true) { System.out.println(""); menu1(); int n = scanner.nextInt(); if (n >= 0 && n <= 6) { if (n == 0) System.exit(0); switch (n) { case 1: principal(); break; case 2: compound_final(); break; case 3: time(); break; case 4: annual_interest_rate(); break; case 5: equal_investment(); break; case 6: Average_repayment(); break; } } else { System.out.println("输入超出范围,请重新输入:"); } } } static Scanner scanner = new Scanner(System.in); static void menu()// 功能介绍函数 { System.out.printf("\t\t|******************************************************|\n"); System.out.printf("\t\t| 利息计算系统 |\n"); System.out.printf("\t\t|******************************************************|\n"); System.out.printf("\t\t| 1: 复利计算 |\n"); System.out.printf("\t\t| 2: 单利计算 |\n"); System.out.printf("\t\t|******************************************************|\n"); System.out.printf("\t请选择<1~2>:"); } static void menu1()// 菜单 { System.out.printf("\t\t|******************************************************|\n"); System.out.printf("\t\t| 1: 本金计算 |\n"); System.out.printf("\t\t| 2: 终值计算 |\n"); System.out.printf("\t\t| 3: 期数计算 |\n"); System.out.printf("\t\t| 4: 利率计算 |\n"); System.out.printf("\t\t| 5: 定期计算 |\n"); System.out.printf("\t\t| 6: 等额本息还款 |\n"); System.out.printf("\t\t|******************************************************|\n"); System.out.printf("请输入你要选择的功能(1~6):"); } static double principal_formula(double S, double i, int Year)// 本金计算公式 { double P; P = S/ Math.pow((1 + i ), Year); return P; } static void principal()// 计算本金 { int Year; double i,P,S; System.out.printf("输入期待复利终值:"); S = scanner.nextDouble(); System.out.printf("年利率:"); i = scanner.nextDouble(); System.out.printf("存入年限:"); Year = scanner.nextInt(); P = principal_formula(S, i, Year); System.out.println("年复利终值为" + S + "需要本金为:" + P); } static double compound_amount_formula(double P, double i, int Year)// 复利计算公式 { double F; F = P * Math.pow((1 + i ),Year); return F; } static void compound_final()// 计算复利终值 { int Year; double i, F, P; System.out.printf("请输入本金:"); P = scanner.nextDouble(); System.out.printf("请输入年利率:"); i = scanner.nextDouble(); System.out.printf("请输入复利次数(年):"); Year = scanner.nextInt(); F = compound_amount_formula(P, i, Year); System.out.println("复利终值:" + F); } static double single_interest_formula(double P, int Year, double i)// 单利计算公式 { double F; F = P *(1+i*Year); return F; } static void single_calate()// 单利计算 { int Year; double i, F, P; System.out.printf("存入本金:"); P = scanner.nextDouble(); System.out.printf("年利率:"); i = scanner.nextDouble(); System.out.printf("存入年限:"); Year = scanner.nextInt(); F = single_interest_formula(P, Year, i); System.out.println("本息和为:" + F); } static int years_formula(double F, double P, double i)// 根据复利终值求年份 { int year; year = (int) (Math.log(F / P) / Math.log(1 + i )); return year; } static void time()// 求年份 { int Year; double i, F, P; System.out.printf("复利终值:"); F = scanner.nextDouble(); System.out.printf("存入本金:"); P = scanner.nextDouble(); System.out.printf("年利率:"); i = scanner.nextDouble(); Year= years_formula(F, P, i); System.out.println("从" + P + "到" + F + "需要" + Year+ "年"); } static double rate_formula(double F, double P, int Year)// 复利的利率计算公式 { double rate; rate = (Math.pow(F / P, 1.0 / Year) - 1); return rate; } static void annual_interest_rate()// 计算年利率 { int Year; double i, F, P; System.out.printf("复利终值:"); F = scanner.nextDouble(); System.out.printf("存入本金:"); P = scanner.nextDouble(); System.out.printf("存入年限:"); Year = scanner.nextInt(); i = rate_formula(F, P, Year); System.out.println("从" + P + "到" + F + "需要" + i); } static double equal_investment_years(double P, int Year, double i)// 按照年份等额投资计算公式 { double final_value; final_value = P * (Math.pow(1 + i, Year) - 1) / i; return final_value; } static double equal_investment_months(double P, int Year, double i)// 按照月份等额投资计算公式 { double final_value; final_value = P * 12 * (1 + i) * (Math.pow(1 + i, Year) - 1) / i; return final_value; } static void equal_investment()// 计算等额投资 { int Year, n; double i, F, P; System.out.printf("\t\t1:按年投资\n\t\t2:按月投资\n"); System.out.printf("请选择你要的功能<1|2>:"); n = scanner.nextInt(); if (n == 1) { System.out.printf("存入本金:"); P = scanner.nextDouble(); System.out.printf("存入年限:"); Year = scanner.nextInt(); System.out.printf("年利率:"); i = scanner.nextDouble(); F = equal_investment_years(P, Year, i); System.out.println(Year+ "年后的总产值:" + F); } else if (n == 2) { System.out.printf("存入本金:"); P = scanner.nextDouble(); System.out.printf("存入年限:"); Year = scanner.nextInt(); System.out.printf("月利率:"); i = scanner.nextDouble(); F = equal_investment_months(P, Year, i); System.out.println(Year + "年后的总产值:" + F); } else { System.out.printf("输入有误!\n"); } } static double equal_repayment_formula(double F, int Year,double i)// 等额还款公式 { double refund; refund = F * i / (12 * (1 + i) * (Math.pow(1 + i, Year) - 1)); return refund; } static void Average_repayment()// 等额还款 { int Year; double i, F, P; System.out.printf("贷款金额:"); F = scanner.nextDouble(); System.out.printf("存入年限:"); Year = scanner.nextInt(); System.out.printf("年利率:"); i = scanner.nextDouble(); P = equal_repayment_formula(F, Year, i); System.out.println("贷款" + F + "每月需要还款" + P); }}

 

转载于:https://www.cnblogs.com/RSTART/p/5339132.html

你可能感兴趣的文章
StackExchange.Redis 官方文档(一) Basics
查看>>
nupkg 之破解 nodejs+electron-packager 打包exe的解包
查看>>
Objective-C 使用 C++类
查看>>
浅谈之高级查询over(partition by)
查看>>
Notes: CRM Analytics–BI from a CRM perspective (2)
查看>>
graphite custom functions
查看>>
列出所有的属性键
查看>>
js获取请求地址后面带的参数
查看>>
[原创]使用java批量修改文件编码(ANSI-->UTF-8)
查看>>
设计模式のCompositePattern(组合模式)----结构模式
查看>>
二进制集合枚举子集
查看>>
磁盘管理
查看>>
SAS学习经验总结分享:篇二—input语句
查看>>
UIImage与UIColor互转
查看>>
RotateAnimation详解
查看>>
系统管理玩玩Windows Azure
查看>>
c#匿名方法
查看>>
如何判断链表是否有环
查看>>
【小程序】缓存
查看>>
ssh无密码登陆屌丝指南
查看>>