Unable to resolve Java error


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: Unable to resolve Java error

  1. #1
    Join Date
    Dec 2006
    Posts
    1

    Question Unable to resolve Java error

    I am trying to complete a program in Java but I can not figure out how to remove 2 errors. The errors seem simple but I have not had any luck resolving them. Desperately trying to get the test program to run. Can anybody help? My code is below.

    // SavingsAccount.java
    // Represents a bank account
    import java.util.Scanner;

    public class SavingsAccount
    {
    private double savingsBalance; // funds available for withdrawal
    private static double annualInterestRate = 0.04; //interest rate
    private double calculateMonthlyInterest;
    private double modifyInterestRate;


    // Account constructor initializes attributes
    public SavingsAccount( double balance ) //
    {
    savingsBalance = balance;
    } // end SavingsAccount constructor

    public void calculateMonthlyInterest ()
    {
    calculateMonthlyInterest = monthlyInterest;
    savingsBalance += ((savingsBalance * annualInterestRate) / 12);
    }

    public void modifyInterestRate (double balance)
    {
    annualInterestRate = balance;
    }

    // returns savings balance
    public double getSavingsBalance()
    {
    return savingsBalance;
    } // end getSavingsBalance


    } // end class Account


    //Program4: SavingsAccountTest.java
    // Create and manipulate an Account object.
    import java.util.Scanner;

    public class SavingsAccountTest
    {
    // main method begins execution of Java application
    public static void main( String args[] )
    {
    //Test class SavingsAccount. Instantiate two savingsAccount objects, saver1 and saver2,
    //with balances of $2000.00 and $3000.00, respectively. Set annualInterestRate to 4%,
    //then calculate the monthly interest and print the new balances for both savers.
    //Then set the annualInterestRate to 5%, calculate the next month's interest and print the new balances for both savers.

    SavingsAccount saver1 = new Account(2000.00); // create Savings Account object
    SavingsAccount saver2 = new Account(3000.00); // create Savings Account object

    //
    saver1.calculateMonthlyInterest(.04);
    saver2.calculateMonthlyInterest();
    System.out.printf( "Saver 1 Savings Balance: $%.2f\n",
    saver1.getSavingsBalance() );
    saver2.calculateMonthlyInterest();
    System.out.printf( "Saver 2 Savings Balance: $%.2f\n",
    saver2.getSavingsBalance() );

    saver1.calculateMonthlyInterest(.05);
    saver2.calculateMonthlyInterest();
    System.out.printf( "Saver 1 Savings Balance: $%.2f\n",
    saver2.calculateMonthlyInterest();
    System.out.printf( "Saver 2 Savings Balance: $%.2f\n",
    saver2.calculateMonthlyInterest();

    } // end main

    } // end class AccountTest

  2. #2
    Join Date
    Jul 2005
    Posts
    78
    what were your errors?

  3. #3
    Join Date
    Aug 2006
    Location
    STL, MO, USA
    Posts
    7
    Like masher said, it's very hard to analyze the script if you do not give us the errors that the compiler noted...

  4. #4
    Join Date
    Dec 2005
    Posts
    97
    from what i can see
    Code:
    SavingsAccount saver1 = new Account(2000.00); // create Savings Account object
    SavingsAccount saver2 = new Account(3000.00); // create Savings Account object
    should be
    Code:
    SavingsAccount saver1 = new SavingsAccount(2000.00); // create Savings Account object
    SavingsAccount saver2 = new SavingsAccount(3000.00); // create Savings Account object
    well thats what i think it should be anyways

  5. #5
    Join Date
    Nov 2006
    Posts
    12
    calculateMonthlyInterest = monthlyInterest;
    What is montlyInterest? I don't see it declared anywhere in your class.
    This code snippet doesn't do anything logical.
    Not to mention that you never set a value for calculateMonthlyInterest, so your going to get whatever garbage is in that memory location and will most likely crash your program. Major logic problem in this method.

    saver1.calculateMonthlyInterest(.05);
    your calculateMonthlyInterest method doesn't take any arguments.

    You don't need to use System.out.printf() because your not giving it a format, print() or println() would workd just as well.

    You import scanner, but never use it, which is a good thing becuase scanner is buggy.
    Last edited by Red_Jester; 12-06-2006 at 11:41 PM.

  6. #6
    Join Date
    Dec 2005
    Posts
    97
    haha, i think those are the correct errors^^^^^

Similar Threads

  1. Error Unable to start debugging on the web server
    By kenn_rosie in forum ASP.NET
    Replies: 3
    Last Post: 12-17-2005, 07:50 PM
  2. Error Handling with java applets
    By kh6gmp in forum Java
    Replies: 4
    Last Post: 05-08-2005, 09:37 AM
  3. Replies: 0
    Last Post: 04-07-2005, 01:31 PM
  4. 'On Error Goto' versus 'Try, Catch, Fail'
    By clarence_rollins in forum .NET
    Replies: 21
    Last Post: 09-11-2002, 11:32 AM
  5. .NET vs. Enterprise Java: Who's Got Better Security?
    By Glen Kunene in forum Talk to the Editors
    Replies: 17
    Last Post: 03-23-2002, 12:43 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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center