this is my code and it says i have problem in line 5 which i couldnt solve . can anyone please help me with this soon!

import java.text.*;

public class SavingsAccount
{
   private double static annualInterestRate;      //declare static variable
   private double savingsBalance;                 //instance variable

   public SavingsAccount(double bal);       //constructor
   {
       savingsBalance= b;
   }
   
   public static double calculateMonthlyInterest()    //calculates monthly interest
   {
     return(savingsBalance * annualInterestRate / 12);
   }
   
   static double modifyInterestRate()        //declare static method
   {
   return annualInterestRate;                //sets annualInterestRate to a new value
   }

   public void showBalance()
   {
      DecimalFormat num = new DecimalFormat(",##.00");
      System.out.print("The balance is $" + num.format);
   }
 public static void main (String[] args)
   {  

   SavingsAccount s1= new SavingsAccount(2000.00);   //instantiate savingsAccount object 1
   SavingsAccount s2= new SavingsAccount(3000.00);  //instantiate savingsAccount object 2
     
   System.out.print("\nThe balance for s1 is ");                    
   s1.calculateMonthlyInterestRate(.04);                      
   
   System.out.print("\nThe balance for s2 is ");                    
   s2.calculateMonthlyInterestRate(.04);
   
    s1.showBalance();                          
   
   
   
  }
}

Use code tags.
If you can't use code tags don't just say the error is at line 5. Try to point out where the error is. What if the error was at line 100. Should we count 100 lines?
And the answer is this:
You wrote:

public SavingsAccount(double bal); //constructor
{
savingsBalance= b;
}

First of all "b" variable is not defined: savingsBalance= [B]b[/B] I believe you meant: savingsBalance= [B]bal[/B] which is the argument of the constructor.

Also you should remove the ';' after the declaration of the constructor: public SavingsAccount(double bal) [B];[/B] //constructor

i appreciate your help as am very new with java coding am facing problem with every step. now with this line i got a new problem " it says cant find symbol" now can u please tell me what went wrong!

System.out.print("The balance is $" + num.format);

Check the API for DecimalFormat.
The error is because "format" doesn't exist as field variable. It says it clearly:
"can't find symbol" Meaning "format" doesn't exist.
Maybe you meant to call it as a method:
num.format() but I am not sure until YOU check the API

cant i do it using double instead of using DecimalFormat?

You can use whatever you want. Did you look at the API?

yes i did.. but it doesnt able to clear my concept am quite confuse now.. and didnt get the solution of my problem yet !

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.