Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

connot resolve symbol-variable calculate

 
Valarie Brandt
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am getting the above error message when i try to compile. calculate is not a variable it is a method but invoiceDate is a method also so i don't see where i went wrong any help that can be offered would be appreciated.
(invoice method which works fine)
public void invoiceDate()
{
invoiceDate = new Date();
SimpleDateFormat formatter = new SimpleDateFormat();
String dateString = formatter.format(invoiceDate);
System.out.println(dateString);
}


public double calculate()
{
double calculate;
calculate = quantity * price;
return calculate;
}
public void display()
{
System.out.println("The invoice date is: "+ invoiceDate +
"\nItem Name: " + name + "\nQuantity: " +quantity +
"\nPrice per item is : " + price + "\nThe total price is: "
+ calculate + ".");
}
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Here there's a method named invoiceDate() that uses a variable named invoiceDate,. This method assigns a value to a variable "invoiceDate" in the first line, but I don't see a declaration for that variable; it would be OK it if were a member, but if not, then you need to say "Date invoiceDate = ..."

This method is fine if quantity and price are member variables; otherwise, it's going to have the same problems.

This method refers to variables named invoiceDate and calculate; I strongly suspect you mean to call the functions invoiceDate() and calculate() here instead like

OK?
 
Valarie Brandt
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you so much--You helped me realize that i needed to call the method name and the method name includes the () right?
thank you

Val
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic