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 ?

java.util.IllegalFormatConversionException: d != java.lang.Double

On line 24, you need to use the correct data type or format code in the printf statement. The format code and the data type don't match.

Read the API doc for the Formatter class to see what the choices are.

commented: Thanks a lot. I started to adore you because whenever i ask a question, you come up with a perfect solution man :) +0

System.out.printf("%d%20d",year,amount);

Thanks a lot. I started to adore you because whenever i ask a question, you come up with a perfect solution man :)

I have changed the code in printf. but still i get error message. i know there is something wrong with printf primitive type but i really could not figuse it out yet. What is wrong with the code below?

System.out.printf("%d%20.2f\n",year,amount);

Do the data types of year and amount match the format codes: d and f?

Look at the API doc to see what d and f are used with.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.