0406复利计算5.0

  1 package kxj;
  2 import java.util.Scanner;
  3
  4 public class Fulijisuan {
  5      public static double p,i,f ;
  6      public static double n;
  7      public static int a=0;
  8
  9      static double A[]  = new double[10];
 10         static double B[]  = new double[10];
 11         static double C[]  = new double[10];
 12         static double D[]  = new double[10];
 13
 14      //计算本金
 15     public static void Benjin(){
 16         //int n;
 17         //float f,i,p;
 18         boolean flag;
 19          Scanner scanner=new Scanner(System.in);
 20           System.out.println("请输入终值: ");
 21           f=scanner.nextDouble();
 22           System.out.println("请输入年利率: ");
 23           i=scanner.nextDouble();
 24           System.out.println("请输入年数: ");
 25           n=scanner.nextInt();
 26           if(n>=0)
 27           {
 28               if(i>=0&&i<=1)
 29               {
 30                  flag=true;
 31                  p=(float) (f*1/Math.pow(1+i, n));
 32               }
 33               else
 34               {
 35                   System.out.println("输入的年利率有错!");
 36                   flag=false;
 37
 38               }
 39           }
 40           else
 41           {
 42               System.out.println("输入的年数有错!");
 43               flag=false;
 44
 45           }
 46           if(flag)
 47               System.out.println("本金为: "+(double)(Math.round(p*100)/100.0));
 48
 49     }
 50
 51     //计算本息和
 52     public static void Benxihe(){
 53          double sum1=0,sum2=0;
 54          boolean flag;
 55           Scanner scanner=new Scanner(System.in);
 56           System.out.println("请输入本金: ");
 57           p=scanner.nextDouble();
 58           System.out.println("请输入年利率: ");
 59           i=scanner.nextDouble();
 60           System.out.println("请输入年数: ");
 61           n=scanner.nextInt();
 62          if(n>=0)
 63           {
 64               if(i>=0&&i<=1)
 65               {
 66                   sum1=(float) (p*Math.pow(1+i, n));
 67                    sum2=p*(1+i*n);
 68                    flag=true;
 69
 70               }
 71               else
 72               {
 73                   System.out.println("输入的年利率有错!");
 74                   flag=false;
 75
 76               }
 77           }
 78           else
 79           {
 80               System.out.println("输入的年数有错!");
 81               flag=false;
 82
 83           }
 84           if(flag)
 85           {
 86              System.out.println("复利的本息和为: "+(double)(Math.round(sum1*100)/100.0));
 87              System.out.println("单利的本息和为: "+(double)(Math.round(sum2*100)/100.0));
 88           }
 89     }
 90
 91     //计算年数
 92     public static void Nianshu(){
 93         boolean flag;
 94           Scanner scanner=new Scanner(System.in);
 95           System.out.println("请输入本金: ");
 96           p=scanner.nextDouble();
 97           System.out.println("请输入终值: ");
 98           f=scanner.nextDouble();
 99           System.out.println("请输入年利率: ");
100           i=scanner.nextDouble();
101          if(i>=0&&i<=1)
102          {
103              n=Logarithm.log(f/p,1+i);
104              flag=true;
105          }
106          else
107          {
108             System.out.println("输入的年利率有错!");
109             flag=false;
110
111          }
112          if(flag)
113           System.out.println("需要存的年数为: "+Math.ceil(n));
114     }
115
116     //计算年利率
117     public static void Lilv(){
118         boolean flag;
119          Scanner scanner=new Scanner(System.in);
120           System.out.println("请输入本金: ");
121           p=scanner.nextDouble();
122           System.out.println("请输入终值: ");
123           f=scanner.nextDouble();
124           System.out.println("请输入年数: ");
125           n=scanner.nextInt();
126          if(n>=0)
127           {
128               i=Math.pow(f/p, 1.0/n)-1;
129               flag=true;
130           }
131           else
132           {
133               System.out.println("输入的年数有错!");
134               flag=false;
135
136           }
137           if(flag)
138           System.out.println("年报酬率为: "+(double)(Math.round(i*1000)/1000.0));
139     }
140
141     //计算本利之和连同年金投资后的总资产
142     public static void Nianjin(){
143         boolean flag;
144          Scanner scanner=new Scanner(System.in);
145           System.out.println("请输入每年定投资金: ");
146           p=scanner.nextDouble();
147           System.out.println("请输入年利率: ");
148           i=scanner.nextDouble();
149           System.out.println("请输入年数: ");
150           n=scanner.nextInt();
151          if(n>=0)
152           {
153               if(i>=0&&i<=1)
154               {
155                    f=p*(1+i)*(Math.pow(1+i,n)-1)/i;
156                    flag=true;
157
158               }
159               else
160               {
161                   System.out.println("输入的年利率有错!");
162                   flag=false;
163
164               }
165           }
166           else
167           {
168               System.out.println("输入的年数有错!");
169               flag=false;
170
171           }
172           if(flag)
173           System.out.println("年资产总值为:"+(double)(Math.round(f*100)/100.0));
174     }
175
176     //计算每月等额本息还款
177     public static void BenxiHuankuan(){
178         double f,i,p = 0;
179         int n;
180         boolean flag;
181          Scanner scanner=new Scanner(System.in);
182           System.out.println("请输入贷款金额: ");
183           f=scanner.nextDouble();
184           System.out.println("请输入年利率: ");
185           i=scanner.nextDouble();
186           System.out.println("请输入贷款年数: ");
187           n=scanner.nextInt();
188          if(n>=0)
189           {
190               if(i>=0&&i<=1)
191               {
192                    i=i/12;
193                    n=n*12;
194                    p=f*i*Math.pow(1+i, n)/(Math.pow(1+i, n)-1);
195                    flag=true;
196
197               }
198               else
199               {
200                   System.out.println("输入的年利率有错!");
201                   flag=false;
202
203               }
204           }
205           else
206           {
207               System.out.println("输入的年数有错!");
208               flag=false;
209
210           }
211           if(flag)
212          System.out.println("每月等额本息还款为:"+(double)(Math.round(p*10000)/10000.0));
213
214     }
215
216      public static void main(String[] args) {
217          int choice;
218          while(true){
219          System.out.println("\t\t|***********************|");
220          System.out.println("\t\t|  1. 求       本      金  \t|");
221          System.out.println("\t\t|  2. 求   本   息   和 \t|");
222          System.out.println("\t\t|  3. 求      年       数 \t|");
223         System.out.println("\t\t|  4. 求      利       率 \t|");
224         System.out.println("\t\t|  5. 求年资产总值\t|");
225         System.out.println("\t\t|  6. 求等额本息还款\t|");
226          System.out.println("\t\t|  7. 投   资   运    算     \t|");
227          System.out.println("\t\t|  0. 退        出          \t|");
228          System.out.println("\t\t|***********************|");
229          Scanner scanner=new Scanner(System.in);
230          System.out.println("\n请输入你的选择(0~7):  ");
231          choice=scanner.nextInt();
232          switch(choice){
233          case 1:
234              Benjin();
235              break;
236          case 2:
237              Benxihe();
238              break;
239          case 3:
240              Nianshu();
241              break;
242          case 4:
243              Lilv();
244              break;
245          case 5:
246              Nianjin();
247              break;
248          case 6:
249              BenxiHuankuan();
250              break;
251          case 7:
252              TouziYunsuan();
253
254              a++;
255              break;
256          case 0:
257              System.out.println("Thanks for using!");
258              System.exit(0);
259              break;
260
261
262          default:
263              {
264                  System.out.println("输入有误!");
265                  break;
266              }
267          }
268              }
269          }
270
271     private static void TouziYunsuan() {
272         boolean flag;
273         int number;
274
275           Scanner scanner=new Scanner(System.in);
276           System.out.println("请输入本金: ");
277           p=scanner.nextDouble();
278           System.out.println("请输入年利率: ");
279           i=scanner.nextDouble();
280           System.out.println("请输入年限: ");
281         n = scanner.nextInt();
282         for (int t = 1; t <= n; t++) {
283             f = p * (1 + i * t);
284
285             System.out.println("第" + t + "年\t  " + (double)(Math.round(f*100)/100.0) + "");
286         }
287         A[a]=p;
288         B[a]=i;
289         C[a]=n;
290         D[a]=f;
291
292         System.out.println("是否查看之前记录(1为是): ");
293         number = scanner.nextInt();
294         if(number==1){
295             System.out.print("\t"+"本金"+"\t"+"年利率"+"\t"+"年限"+"\t"+"终值"+"\n");
296             for(int b=0;b<=a;b++)
297             {
298                 System.out.print(b+1+"\t"+A[b]+"\t"+B[b]+"\t"+C[b]+"\t"+D[b]+"\n");
299
300             }
301
302         }
303         else{
304             System.out.print("谢谢");
305
306         }
307     }
308      }
1 package kxj;
2
3 public class Logarithm {
4      static public double log(double value, double base){
5             return Math.log(value)/Math.log(base);
6
7          }
8 }

时间: 2024-07-30 20:29:27

0406复利计算5.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,

复利计算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

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.复利计

复利计算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"