• Post Reply Bookmark Topic Watch Topic
  • New Topic

Calling methods from another class  RSS feed

 
George McCoy
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, I'm working on an assignment where I have to call methods, setters and getters from a class file called CustomerOrder. CustomerOrder was written by the professor and I have to use the javadocs to decide what methods and stuff to use. The only problem I'm having is with the method calcDiscount. The javadocs info is:

Method name: calcDisocunt()
Returns: double
Purpose: Calculates the user's discount based on their discount status.


This is just the snip of code I'm having trouble with but I can post the entire thing if you want. It's kind of long and everything else is working so I didn't want to clog up the page unnecessarily.



The line

CustomerOrder.calcDiscount();

keeps giving me the error "non-static methods cannot be accessed from a static context." Any idea how to fix it? Obviously my main method is static so should I change that? I've never done that before though so I might need a bit of help if that's the solution.
 
George McCoy
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never mind. I figured it out. Feel free to lock/delete this.
 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to create an instance (object) of the the CustomerOrder class using the new keyword, then access the method from that.
 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And Welcome the the Ranch. Would you like to post what you did?
 
George McCoy
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:And Welcome the the Ranch. Would you like to post what you did?

Sure. I changed to and now it's working. I guess I should have posted the entire thing after all since I left out the part where I name the order. Oops. You all probably would have figured it out but it was still kind of dumb of me to forget that.
 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nice job. If you feel you would like some helpful comments on your code, post it all here. We'll be gentle!
 
George McCoy
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just finished this project but I'll probably need help in the future. Thanks!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!