Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

connot resolve symbol-variable calculate

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 + ".");
}
 
author and iconoclast
Posts: 24203
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic