Results 1 to 3 of 3
  1. #1
    AprilFlowers is offline Member
    Join Date
    Oct 2009
    Posts
    2
    Rep Power
    0

    Default Calculating compound interest using ONLY integers.

    I have an assignment to alter a previous assignment (compounding interest over 10 years at 5%) by only using integers.
    So i know that 5% is equal to dividing by 100 and multiplying by 5. And I know I have to convert it back from pennies to dollars. I tried using the Math.pow but it just gave me a lot more errors. I am just lost, I'm not very good at this. If someone could give me a hint and let me know where to go from here, I would appreciate it. Right now it just prints "Year Amount on Deposit" and then says:

    1Exception in thread "main" java.util.IllegalFormatConversionException: f != java.lang.Integer
    at java.util.Formatter$FormatSpecifier.failConversion (Formatter.java:3992)
    at java.util.Formatter$FormatSpecifier.printFloat(For matter.java:2721)
    at java.util.Formatter$FormatSpecifier.print(Formatte r.java:2666)
    at java.util.Formatter.format(Formatter.java:2432)
    at java.io.PrintStream.format(PrintStream.java:920)
    at java.io.PrintStream.printf(PrintStream.java:821)
    at InterestTwo.main(InterestTwo.java:22)

    This is my code:

    // Fig. 5.6: InterestTwo.java
    // Compound interest calculations with for using only integers

    public class InterestTwo
    {
    public static void main( String[] args )
    {
    int amount = 0; // amount on deposit at end of each year
    int principal = 100000; // initial amount before interest
    int rate = 5; // interest rate

    //display headers
    System.out.printf( "%s%20s\n", "Year", "Amount on deposit" );

    // calculate amount on deposit for each of ten years
    for ( int year = 1; year <= 10; year++ )
    {
    // calculate new amount for specified year
    amount = principal / 100 * rate;

    // display the year and the amount
    System.out.printf( "%4d%,20.2f\n", year, amount );
    } // end for
    } // end main
    } // end class InterestTwo.java



    *sigh* thanks

  2. #2
    [RaIdEn] is offline Senior Member
    Join Date
    Oct 2009
    Location
    California,US
    Posts
    201
    Rep Power
    6

    Default

    Quote Originally Posted by AprilFlowers View Post
    I have an assignment to alter a previous assignment (compounding interest over 10 years at 5%) by only using integers.
    So i know that 5% is equal to dividing by 100 and multiplying by 5. And I know I have to convert it back from pennies to dollars. I tried using the Math.pow but it just gave me a lot more errors. I am just lost, I'm not very good at this. If someone could give me a hint and let me know where to go from here, I would appreciate it. Right now it just prints "Year Amount on Deposit" and then says:

    1Exception in thread "main" java.util.IllegalFormatConversionException: f != java.lang.Integer
    at java.util.Formatter$FormatSpecifier.failConversion (Formatter.java:3992)
    at java.util.Formatter$FormatSpecifier.printFloat(For matter.java:2721)
    at java.util.Formatter$FormatSpecifier.print(Formatte r.java:2666)
    at java.util.Formatter.format(Formatter.java:2432)
    at java.io.PrintStream.format(PrintStream.java:920)
    at java.io.PrintStream.printf(PrintStream.java:821)
    at InterestTwo.main(InterestTwo.java:22)

    This is my code:

    // Fig. 5.6: InterestTwo.java
    // Compound interest calculations with for using only integers
    Java Code:
    public class InterestTwo
    {
    	public static void main( String[] args )
    	{
    		int amount = 0; // amount on deposit at end of each year
    		int principal = 100000; // initial amount before interest
    		int rate = 5; // interest rate
    		
    		//display headers
    		System.out.printf( "%s%20s\n", "Year", "Amount on deposit" );
    		
    		// calculate amount on deposit for each of ten years
    		for ( int year = 1; year <= 10; year++ )
    		{
    			// calculate new amount for specified year
    			amount = principal / 100 * rate;
    			
    			// display the year and the amount
    			System.out.printf( "%4d%,20.2f\n", year, amount );
    		} // end for
    	} // end main
    } // end class InterestTwo.java
    *sigh* thanks
    Java Code:
    System.out.printf( "%s%20s\n", "Year", "Amount on deposit" );
    	
           System.out.printf( "%4d%,20.2f\n", year, amount );
    that format seems to be similar to c

    in java you dont declare"%d" etc , instead
    Java Code:
    //display headers
    System.out.printf( "Year\n"+ "Amount on deposit\n" );
    
    // display the year and the amount
    System.out.printf( "Year:"+ year+"\n"+"\nAmount"+ amount );
    is enough

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Help with compound interest program pleaze
    By Smirre in forum New To Java
    Replies: 1
    Last Post: 01-19-2009, 09:31 PM
  2. HELP FAST!!----Interest Calculator
    By Coop33 in forum New To Java
    Replies: 8
    Last Post: 10-15-2008, 01:44 PM
  3. calculating Bank interest rate.
    By dotnet007 in forum New To Java
    Replies: 10
    Last Post: 05-13-2008, 09:30 AM
  4. How to use compound property names in Spring
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-30-2008, 10:08 AM
  5. How to use compound property names in Spring
    By JavaBean in forum Java Tip
    Replies: 0
    Last Post: 09-26-2007, 08:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •