import java.util.Scanner;
public class Interest {
public void determineInterest(){
Scanner input = new Scanner(System.in);
double amount;
double rate1 = 0.05;
double rate2 = 0.06;
double rate3 = 0.07;
double rate4 = 0.08;
double year;
double principal = 1000;
System.out.println("Please choose your bank below:\na)Ziraat Bankasi\nb)Halk Bankasi\nc)Is bankasi\nd)City Bank");
String bankname = input.nextLine();
System.out.println("Year\tAmount");
if (bankname.equalsIgnoreCase("a")){
for (year = 1; year <= 10; year++){
amount = principal * Math.pow(1 + rate1, year);
System.out.printf("%d%20d",year,amount);
System.out.println("For your information, These values are Ziraat Bank's values...");
}//While loop end.
}else if (bankname.equalsIgnoreCase("b")){
for (year = 1; year <= 10; year++){
amount = principal * Math.pow(1 + rate2, year);
System.out.printf("%d%20d",year,amount);
System.out.println("For your information, These values are Halk Bank's values...");
}//While loop end.v
}else if (bankname.equalsIgnoreCase("c")){
for (year = 1; year <= 10; year++){
amount = principal * Math.pow(1 + rate3, year);
System.out.printf("%d%20d",year,amount);
System.out.println("For your information, These values are Is Bank's values...");
}//While loop end.
}else if (bankname.equalsIgnoreCase("d")){
for (year = 1; year <= 10; year++){
amount = principal * Math.pow(1 + rate4, year);
System.out.printf("%d%20d",year,amount);
System.out.println("For your information, These values are City Bank's values...");
}//While loop end.
}else System.out.println("Your did not choose one of the options. Please try again.");
}//Method end.
}//Class end.
public class InterestTest {//new class.
public static void main(String[] args){
Interest myInterest = new Interest();
myInterest.determineInterest();
}//method end.
}//Class end
In this code , i am getting an error message like this. Please choose your bank below:
Please choose your bank below:
a)Ziraat Bankasi
b)Halk Bankasi
c)Is bankasi
d)City Bank
A
Year Amount
Exception in thread "main" java.util.IllegalFormatConversionException: d != java.lang.Double
at java.util.Formatter$FormatSpecifier.failConversion(Formatter.java:3999)
at java.util.Formatter$FormatSpecifier.printInteger(Formatter.java:2709)
at java.util.Formatter$FormatSpecifier.print(Formatter.java:2661)
at java.util.Formatter.format(Formatter.java:2433)
at java.io.PrintStream.format(PrintStream.java:920)
at java.io.PrintStream.printf(PrintStream.java:821)
at Interest.determineInterest(Interest.java:24)
at InterestTest.main(InterestTest.java:7)
I did not understand why. Can anybody please help me ?