复利计算器
import java.util.Scanner; public class Fulijisuan { public static void main(String[] args) { // TODO Auto-generated method stub double F=0; double singlesum=0; double doublesum=0; double m=0; Scanner scanner =new Scanner(System.in); System.out.println("1:复利计算\n2:单利计算\n3:复利计算求本金\n4:复利计算求年限\n5:复利计算求年率"); System.out.println("6:复利计算每年定投"); System.out.print("请输入您要求的:"); int n = scanner.nextInt(); switch (n){ case 1: System.out.print("请输入你本金:"); double p = scanner.nextDouble(); System.out.print("请输入您的利率:"); double i = scanner.nextDouble(); System.out.print("请输入您的年限:"); double year = scanner.nextDouble(); for(int j=1;j<=year;j++){ F=p*i; p=p+F; } doublesum=p; System.out.print("复利后的终值为"+doublesum+""); break; case 2: System.out.print("请输入你本金:"); double p2 = scanner.nextDouble(); System.out.print("请输入您的利率:"); double i2 = scanner.nextDouble(); System.out.print("请输入您的年限:"); double year2 = scanner.nextDouble(); for(int j=1;j<=year2;j++){ F=p2*i2; m=m+F; } singlesum=p2+m; System.out.print("单利后的终值为"+singlesum+""); break; case 3: System.out.print("请输入你总额:"); double sum = scanner.nextDouble(); System.out.print("请输入你利率:"); double i3 = scanner.nextDouble(); System.out.print("请输入你期限:"); double year3 = scanner.nextDouble(); i3=1+i3; for(int j=1;j<=year3;j++){ sum=sum/i3; } p=sum; System.out.print("应存本金为"+p+""); break; case 4: int year4=0; System.out.print("请输入你本金:"); double p4 = scanner.nextDouble(); System.out.print("请输入你利率:"); double i4 = scanner.nextDouble(); System.out.print("请输入你总额:"); double sum4 = scanner.nextDouble(); while(p4<sum4){ for(int j=1;j<100;j++);{ p4=p4*(1+i4); year4++; } } System.out.print("到"+sum4+"的时间要"+year4+"年"); break; case 5: double i5; System.out.print("请输入你本金:"); double p5 = scanner.nextDouble(); System.out.print("请输入你总额:"); double sum5 = scanner.nextDouble(); System.out.print("请输入你期限:"); double year5 = scanner.nextDouble(); i5=Math.pow(sum5/p5, 1/year5)-1; System.out.print("在"+year5+"年内从"+p5+"到"+sum5+"的利率为:"+(float)i5+""); break; case 6: System.out.print("请输入你本金:"); double p6 = scanner.nextDouble(); System.out.print("请输入你利率:"); double i6 = scanner.nextDouble(); System.out.print("请输入你期限:"); double year6 = scanner.nextDouble(); double F6=p6; for(int j=1;j<=year6;j++){ p6=p6*(1+i6); if(year6!=j) p6=p6+F6; } System.out.print("每年定投的产生的总额:"+p6+""); } } }
实验回顾
对于我这种编写代码能力有限的同学来说 这个复利计算器的实现 有点难度,所以是在同学帮助下完成的。。。博客简短;水平有限.望老师们见谅,我会在接下来的学习过程中慢慢提高自己的编码能力的。