Results 1 to 2 of 2
  1. #1
    jm_scion is offline Member
    Join Date
    Dec 2013
    Posts
    1
    Rep Power
    0

    Default Emergency exam help - calculating interest

    Hey guys, yeah this is another homework help request, but I'm really at a loss here. I'm supposed to write a script that will calculate balances after interest rates and output them over a 12 month period.

    I'm at a brick wall. The script I have compiles just fine, but when executed with the test file I get an error that the value for saver1 and saver2 is an incompatible type. I can't find what I'm missing here. Can anybody point me in the right direction?

    Here is the utility script. The error is somewhere in here.
    Java Code:
    public class SavingAccount
    {
       // interest rate for all accounts
       private static double annualInterestRate = 0;
       
       private double savingsBalance; // balance for currrent account
    
       // constructor, creates a new account with the specified balance
       public void SavingAccount( double savingsBalance )
       {
          savingsBalance = savingsBalance;
       } // end constructor
    
       // get monthly interest 
       public void calculateMonthlyInterest()
       {
          savingsBalance += savingsBalance * ( annualInterestRate / 12.0 );
       } // end method calculateMonthlyInterest
       
       // modify interest rate
       public static void modifyInterestRate( double newRate )
       {
          annualInterestRate = 
             ( newRate >= 0 && newRate <= 1.0 ) ? newRate : 0.04;
       } // end method modifyInterestRate
    
       // get string representation of SavingAccount
       public String toString()
       {
          return String.format( "$%.2f", savingsBalance );
       } // end method toSavingAccountString
    } // end class SavingAccount
    And this is the file that's supposed to test it.

    Java Code:
    public class SavingAccountTest
    {
       public static void main( String args[] )
       {
          SavingAccount saver1 = new SavingAccount( 2000 );
          SavingAccount saver2 = new SavingAccount( 3000 );
          SavingAccount.modifyInterestRate(0.04);
    
          System.out.println( "Monthly balances for one year at .04" );
          System.out.println( "Balances:" );
          
          System.out.printf( "%20s%10s\n", "Saver 1", "Saver 2" );
          System.out.printf( "%-10s%10s%10s\n", "Base",
             saver1.toString(), saver2.toString() );
          
          for ( int month = 1; month <= 12; month++ )
          {
             String monthLabel = String.format( "Month %d:", month );
             saver1.calculateMonthlyInterest();
             saver2.calculateMonthlyInterest();
    
             System.out.printf( "%-10s%10s%10s\n", monthLabel,
                saver1.toString(), saver2.toString() );
          } // end for
    
          SavingAccount.modifyInterestRate( .05 );
          saver1.calculateMonthlyInterest();
          saver2.calculateMonthlyInterest();
          
          System.out.println( "\nAfter setting interest rate to .05" );
          System.out.println( "Balances:" );
          System.out.printf( "%-10s%10s\n", "Saver 1", "Saver 2" );
          System.out.printf( "%-10s%10s\n",
             saver1.toString(),  saver2.toString() );
       } // end main
    } // end class SavingAccountTest

    Thanks in advance!
    Last edited by jm_scion; 12-15-2013 at 12:37 AM. Reason: Cut off code

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,784
    Rep Power
    5

    Default Re: Emergency exam help - calculating interest

    Take a close look at your constructor and think about constructor syntax. Also think about what you are doing within that constructor.

    Regards,
    Jim
    Last edited by jim829; 12-15-2013 at 03:23 AM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. fibbonacci series- please its emergency
    By zoala001 in forum Java Applets
    Replies: 5
    Last Post: 01-14-2011, 12:58 PM
  2. Replies: 0
    Last Post: 03-28-2010, 09:55 AM
  3. Calculating compound interest using ONLY integers.
    By AprilFlowers in forum New To Java
    Replies: 2
    Last Post: 10-21-2009, 06:47 AM
  4. calculating Bank interest rate.
    By dotnet007 in forum New To Java
    Replies: 10
    Last Post: 05-13-2008, 09:30 AM

Posting Permissions

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