Here is my method in a separate class:
Main method in seperate class:
Error message should tell you what is wrong and in which line wrong things most likely heppened. So, please copy error message and post here exactly as it appears (not a screenshot, just a text).
Dustin Boor wrote:When I try to do it in my IDE I get a syntax error. When I try to call temp1.calculatePay(hours, payRate, grossPay) I get an error. What am I doing wrong?
Also, since the method you call is static, it's not a good practice to call it via a reference to an instance object like temp or temp1.
Names like TestClass and temp are not very informative. you should choose names that better reflect their purpose or the idea they represent, like calculatePay, which is a decent name for that method.
Your calculatePay method takes a grossPay parameter when it shouldn't. The grossPay should be a local variable, not a parameter. Parameters are things you need to do something. Grosspay is the value you want to calculate based on the given hours and pay rate.
Campbell Ritchie wrote:You can make grossPay a local variable in that method, as an alternative. Are you using Eclipse? Please realise that the many suggestions given when you click the red mark are suggestions. You need to decide which to use, if any.
I am not using Eclipse, I am using IntelliJ. I am starting to see the suggestions now. Thank you.
The one case you really need to be aware of is when you get a “resource leak” warning for this sort of code:-
Scanner keyboardIn = new Scanner(System.in);
If you are reading from System.in you must ignore the suggestion to close that Scanner. Similarly, never close System.out and System.err. Maybe the suggestion to tag the code with @SuppressWarnings is better. You don't get many chances to use @SuppressWarnings. You must close Scanners reading from files, sockets, etc., however.