-
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
-
-
Like masher said, it's very hard to analyze the script if you do not give us the errors that the compiler noted...
-
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
-
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.
-
haha, i think those are the correct errors^^^^^
Similar Threads
-
By kenn_rosie in forum ASP.NET
Replies: 3
Last Post: 12-17-2005, 07:50 PM
-
Replies: 4
Last Post: 05-08-2005, 09:37 AM
-
Replies: 0
Last Post: 04-07-2005, 01:31 PM
-
By clarence_rollins in forum .NET
Replies: 21
Last Post: 09-11-2002, 11:32 AM
-
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks