954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

problem with identifier error problem!

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();                          
   
   
   
  }
}
samrin
Newbie Poster
8 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

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= <strong>b</strong>
I believe you meant: savingsBalance= <strong>bal</strong> which is the argument of the constructor.

Also you should remove the ';' after the declaration of the constructor: public SavingsAccount(double bal) <strong>;</strong> //constructor

javaAddict
Nearly a Senior Poster
Team Colleague
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
 

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);

samrin
Newbie Poster
8 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

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

javaAddict
Nearly a Senior Poster
Team Colleague
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
 

cant i do it using double instead of using DecimalFormat?

samrin
Newbie Poster
8 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

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

javaAddict
Nearly a Senior Poster
Team Colleague
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
 

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

samrin
Newbie Poster
8 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You