码迷,mamicode.com
首页 > 其他好文 > 详细

0330复利计算4.0(改)

时间:2016-03-31 00:04:56      阅读:237      评论:0      收藏: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 }

 

0330复利计算4.0(改)

标签:

原文地址:http://www.cnblogs.com/xjy-gg/p/5339347.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!