0330复利计算4.0(改)

  1 import java.util.Scanner;
  2
  3 public class text {
  4
  5     public static void main(String[] args) {
  6         while (true) {
  7             Scanner scanner = new Scanner(System.in);
  8             System.out.println("----------------------------");
  9             System.out.println("    1.复利计算本息                          ");
 10             System.out.println("    2.单利计算本息                          ");
 11             System.out.println("    3.复利计算本金                          ");
 12             System.out.println("    4.单利计算本金                          ");
 13             System.out.println("    5.算投资年限      ");
 14             System.out.println("    6.算投资年利率      ");
 15             System.out.println("    7.每年定投收益                       ");
 16             System.out.println("    8.每月定投收益                       ");
 17             System.out.println("    9.每月等额本息还款          ");
 18             System.out.println("    0.退出                             ");
 19             System.out.println("----------------------------");
 20             System.out.print("请选择:");
 21             int number = scanner.nextInt();
 22             switch (number) {
 23             case 1:
 24                 BenxiFuli();
 25                 break;
 26             case 2:
 27                 BenxiDanli();
 28                 break;
 29             case 3:
 30                 BenjinFuli();
 31                 break;
 32             case 4:
 33                 BenjinDanli();
 34                 break;
 35             case 5:
 36                 TouziYear();
 37                 break;
 38             case 6:
 39                 TouziRate();
 40                 break;
 41             case 7:
 42                 YearDingtoushouyi();
 43                 break;
 44             case 8:
 45                 MonthDingtoushouyi();
 46                 break;
 47             case 9:
 48                 Dengerbenxihuanknan();
 49                 break;
 50             case 0:
 51                 Exit();
 52                 break;
 53             default: {
 54                 System.out.println("输入错误!请重新输入!");
 55                 break;
 56             }
 57             }
 58         }
 59
 60     }
 61
 62     private static void Exit() {
 63         // TODO 自动生成的方法存根
 64         System.out.println("谢谢使用!");
 65         System.exit(0);
 66
 67     }
 68
 69     private static void Dengerbenxihuanknan() {
 70         // TODO 自动生成的方法存根
 71         Scanner scanner = new Scanner(System.in);
 72         System.out.print("请输入贷款本金:");
 73         double money = scanner.nextDouble();
 74         System.out.print("请输入年利率:");
 75         double rate = scanner.nextDouble();
 76         System.out.print("请输入年限:");
 77         int year = scanner.nextInt();
 78         double num = 1;
 79         for (int i = 1; i <= year * 12; i++) {
 80             num = (1 + (rate / 12)) * num;
 81
 82         }
 83         money = money * ((rate / 12) * num) / (num - 1);
 84         System.out.println("每月等额本息还款:"
 85                 + (double) (Math.round(money * 100) / 100.0));
 86
 87     }
 88
 89     private static void MonthDingtoushouyi() {
 90         // TODO 自动生成的方法存根
 91         Scanner scanner = new Scanner(System.in);
 92
 93         System.out.print("请输入每月的定投金额:");
 94         double money = scanner.nextDouble();
 95         System.out.print("请输入年利率:");
 96         double rate = scanner.nextDouble();
 97         System.out.print("请输入年限:");
 98         int year = scanner.nextInt();
 99         double num = 1;
100         for (int i = 1; i <= year * 12; i++) {
101             num = (1 + (rate / 12)) * num;
102
103         }
104         money = money * (1 + (rate / 12)) * (-1 + num) / (rate / 12);
105         System.out.println("定投" + year + "年后的资产总值为:"
106                 + (double) (Math.round(money * 100) / 100.0));
107
108     }
109
110     private static void YearDingtoushouyi() {
111         // TODO 自动生成的方法存根
112         Scanner scanner = new Scanner(System.in);
113
114         System.out.print("请输入每年的投资金额:");
115         double money = scanner.nextDouble();
116         System.out.print("请输入年利率:");
117         double rate = scanner.nextDouble();
118         System.out.print("请输入年限:");
119         int year = scanner.nextInt();
120         double num = 1;
121         for (int i = 1; i <= year; i++) {
122             num = (1 + rate) * num;
123
124         }
125         money = money * (1 + rate) * (-1 + num) / rate;
126         System.out.println("定投" + year + "年后的资产总值为:"
127                 + (double) (Math.round(money * 100) / 100.0));
128
129     }
130
131     private static void TouziRate() {
132         // TODO 自动生成的方法存根
133         Scanner scanner = new Scanner(System.in);
134         System.out.print("请输入投资金额:");
135         double money1 = scanner.nextDouble();
136         System.out.print("请输入收获金额:");
137         double money2 = scanner.nextDouble();
138
139         System.out.print("请输入年限:");
140         int year = scanner.nextInt();
141         double rate;
142         rate = Math.pow(money2 / money1, 1.0 / year) - 1;
143         System.out.println("所需年利率为:"
144                 + (double) (Math.round(rate * 10000) / 10000.0));
145
146     }
147
148     private static void TouziYear() {
149         // TODO 自动生成的方法存根
150         Scanner scanner = new Scanner(System.in);
151         System.out.print("请输入投资金额:");
152         double money1 = scanner.nextDouble();
153         System.out.print("请输入收获金额:");
154         double money2 = scanner.nextDouble();
155
156         System.out.print("请输入年利率:");
157         double rate = scanner.nextDouble();
158         double year;
159         year = Logarithm.log(money2 / money1, 1 + rate);
160         year = Math.ceil(year);
161         System.out.println("需要存入的年限为:" + year);
162
163     }
164
165     private static void BenjinDanli() {
166         // TODO 自动生成的方法存根
167         Scanner scanner = new Scanner(System.in);
168         System.out.print("请输入本息:");
169         double money = scanner.nextDouble();
170         System.out.print("请输入年利率:");
171         double rate = scanner.nextDouble();
172         System.out.print("请输入年限:");
173         int year = scanner.nextInt();
174         money = money * (1 / (1 + rate * year));
175         System.out.println("单利计算需要存入的本金为:"
176                 + (double) (Math.round(money * 100) / 100.0));
177
178     }
179
180     private static void BenjinFuli() {
181         // TODO 自动生成的方法存根
182         Scanner scanner = new Scanner(System.in);
183         System.out.print("请输入本息:");
184         double money = scanner.nextDouble();
185         System.out.print("请输入年利率:");
186         double rate = scanner.nextDouble();
187         System.out.print("请输入年限:");
188         int year = scanner.nextInt();
189         double num = 1;
190         for (int i = 1; i <= year; i++) {
191             num = num * (1 + rate);
192         }
193         money = money * (1 / num);
194         System.out.println("复利计算需要存入的本金为:"
195                 + (double) (Math.round(money * 100) / 100.0));
196
197     }
198
199     private static void BenxiDanli() {
200         // TODO 自动生成的方法存根
201         Scanner scanner = new Scanner(System.in);
202         System.out.print("请输入本金:");
203         double money = scanner.nextDouble();
204         System.out.print("请输入年利率:");
205         double rate = scanner.nextDouble();
206         System.out.print("请输入年限:");
207         int year = scanner.nextInt();
208         money = money + money * rate * year;
209         System.out.println("存入" + year + "年后的单利计算本息为:"
210                 + (double) (Math.round(money * 100) / 100.0));
211
212     }
213
214     private static void BenxiFuli() {
215         // TODO 自动生成的方法存根
216         Scanner scanner = new Scanner(System.in);
217         System.out.print("请输入本金:");
218         double money = scanner.nextDouble();
219         System.out.print("请输入年利率:");
220         double rate = scanner.nextDouble();
221         System.out.print("请输入年限:");
222         int year = scanner.nextInt();
223         for (int i = 1; i <= year; i++) {
224             money = (1 + rate) * money;
225         }
226         System.out.println("存入" + year + "年后的复利计算本息为:"
227                 + (double) (Math.round(money * 100) / 100.0));
228
229     }
230 }
时间: 2024-10-07 05:16:31

0330复利计算4.0(改)的相关文章

0330复利计算4.0单元测试

测试模块 输入测试 预期结果 运行结果 复/单利计算本息  (本金,年利率,年限)      1000,0.03,10 复利:1343.92 单利:1300.0 √  0,0.03,10 复利:0.0 单利:0.0   √  1000,0,10 复利:1000.0 单利:1000.0  √  1000,0.03,10 复利:1000.0 单利:1000.0  √ 复/单利计算本金   (本息,年利率,年限)      1000,0.03,10 复利:744.09 单利:769.23  √  0,

复利计算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("\n复利计算按 1\n单利计算按 2\n计算筹集的养老金按 3\n计算时间按 4\n计算您要的利率按 5\n计算本利和投资按 6\n计算

复利计算4.0单元测试

——————————复利计算程序单元测试报告—————————— ————————————4.0 单元测试—————————————— ————————————————要求—————————————— 根据复利计算程序,进行Junit单元测试. 在测试会出现什么场面,有哪些情况的结果? 所要期待的返回值是多少? 写测试程序. 运行测试. 完成结果: 测试一:复利计算本息 1.期待的返回值是13439,实际值是13439.16,允许有1.0以内的误差. 2.测试程序: 此为复利计算: 在允许误差为

复利计算6.0

一.主要功能与需求分析 1.本金为100万,利率或者投资回报率为3%,投资年限为30年,那么,30年后所获得的利息收入:按复利计算公式来计算就是:1,000,000×(1+3%)^30 2.如果按照单利计算,本息的最终收益 3.假如30年之后要筹措到300万元的养老金,平均的年回报率是3%,那么,现在必须投入的本金是多少呢? 4.利率这么低,复利计算收益都这么厉害了,如果拿100万元去买年报酬率10%的股票,若一切顺利,过多长时间,100万元就变成200万元呢? 5.如果我希望在十年内将100万

复利计算3.0代码

#include<stdio.h> #include<math.h> void List(); void A(); void B(); void C(); void D(); void E(); void F(); main() { int sel; List(); printf("\t请选择:"); while(scanf("%d",&sel)!=1||sel<0||sel>6)//防止输入的是字符以及输入的数字不是整数

0317复利计算3.0

1 import java.util.Scanner; 2 3 public class text { 4 public static void main(String[] args) { 5 6 7 do { 8 Scanner scanner = new Scanner(System.in); 9 System.out.println(" "); 10 System.out.print("请选择(0为退出,1为算本息,2为算本金,3为算投资,4为算n年后资产总值):&qu

复利计算3.0

import java.util.Scanner; public class Money { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("请输入计算方式:1.单利计算 2.复利计算 3.本金计算 4.股票期限计算 5.利率计算 6.资产总值计算"); // 选择计算方式 int choose = scanner.nextInt

复利计算2.0

1 package fulijisuan; 2 3 import java.awt.event.MouseAdapter; 4 import java.awt.event.MouseEvent; 5 6 import javax.swing.JButton; 7 import javax.swing.JFrame; 8 import javax.swing.JLabel; 9 import javax.swing.JRadioButton; 10 import javax.swing.JText

复利计算1.0,2.0

1.客户说:帮我开发一个复利计算软件. 完成复利公式计算程序,并成功PUSH到github上. 截止时间:3.10晚12点之前. 按照这个要求完成了. 演示. 计算:本金为100万,利率或者投资回报率为3%,投资年限为30年,那么,30年后所获得的利息收入:按复利计算公式来计算就是:1,000,000×(1+3%)^30 #include<stdio.h> #include<math.h> void view() { printf(" | 单/复利计算 |\n"