Savings Account Class

I'm having trouble figuring out a program for Java.

Heres the problem:

Create class SavingsAccount. Use a static variable annualInterestRate to store the annual interest rate for all account holders. Each object of the class contains a private instance variable savingsBalance indicating the amount the saver currently has on deposit. Provide method calculateMontlyInterest to calculate the monthly interest by multiplying the savingsBalance by annualInterestRate divided by 12this interest rate should be added to savingsBalance. Provide a static method modifyInterestRate that sets the annualInterestRate to a new value. Write a program to 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.

Here is what I have so far:

import java.util.Scanner;

public class SavingsAccount

{

private static int annualInterestRate = .04;

private static int savingsBalance;

private static int

double saver1 = 2000.00;

double saver2 = 3000.00;

public static void main( String[] args)

{

Scanner input = new Scanner ( System.in );

I know this isn't much, but I'm having trouble implementing the methods and private variables it is asking for.

I've been driving myself crazy trying to figure this out with no luck, so any help would be greatly appreciated.

Thanks, James.

[1684 byte] By [diedeadenougha] at [2007-11-27 1:07:26]
# 1

Here are a few tips based on what you have written.

1. You did, indeed define a SavingsAccount class.

2. You did, indeed, define a static field to hold the interest rate (which applies to all instances.

3. But you made the savingsBalance static. I don't think you want that - you want every instance to have its own balance.

4. Some kind of incomplete int definition?

5. Savers are not parts of accounts. If anything, you might think of each saver as an account.

6. So give your savings account a way to be initialized with a balance. For example, how about a constructor to set the balance?

7. Now your test program: It should instantiate a couple of instances of SavingsAccount. you might even call them saver1 and saver2.

8. Now go back and give your SavingsAccount class methods to do what the problem requested: calculate interest, change interest rate, etc.

bschauwejavaa at 2007-7-11 23:42:41 > top of Java-index,Java Essentials,Java Programming...