所以基本上其他所有东西都起作用,它只是频率部分,必须是每年,每半年,每季度或每月,所有这些都在代码中,我只是不知道如何将它们全部放在计算部分中,以防将来和将来和案例。
package compound;
import java.util.Scanner;
public class Compound {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double total;
double rate;
double amount;
String optRate = "optRate";
double fixedRated = 0;
double time;
double n = 0;
String presOrFut = "presOrFut";
String timed = "timed";
String freq = "freq";
double frequency = 0;
System.out.println("please enter amount: ");
amount = scanner.nextDouble();
System.out.println("please enter the rate: ");
rate = scanner.nextDouble();
System.out.println("rate of daily, monthly or yearly?");
optRate = scanner.next();
switch (optRate) {
case "daily":
fixedRated = rate / 365;
case "monthly":
fixedRated = rate / 12;
case "yearly":
fixedRated = rate / 1;
}
//this is my compounding freq which doesnt work
// System.out.println("please enter the compounding frequency: annualy, Semi-annualy, quartly or monthly");
// freq = scanner.next();
// switch (freq){
// case "annually":
// frequency = fixedRated/1;
// case "semi":
// frequency = fixedRated/2;
// case "quartly":
// frequency = fixedRated/4;
// case "mothly":
// frequency = fixedRated/12;
// }
System.out.println("enter the lenght of term: ");
time = scanner.nextDouble();
System.out.println("is it daily, monthly or yearly");
timed = scanner.next();
switch (timed) {
case "daily":
n = time * 365;
case "monthly":
n = time * 12;
case "yearly":
n = time * 1;
}
System.out.println("future value at end of term or present value? ");
presOrFut = scanner.next();
switch (presOrFut) {
case "future":
total = amount * (Math.pow((1 + fixedRated/100),n));
case "present":
total = amount / (Math.pow((1 + fixedRated/100),n));
System.out.println("your total is :"+ total);
}
}
}