Hi everyone! I am new to Java. I'm working on my third program, but I think there are still pieces of syntax, etc... that I must be missing because I can't get it to work right. This is homework, and although my teacher doesn't care if I get a little help, he would be very cross if you gave me the "answer", so really what I'm asking for is just a little nudge in the right direction. The specific problem that I need help with is that when I run the driver file (PayRoll.java), it entirely ignores the " empl1.totalPay();" and "empl2.totalPay();" lines of code. I tried changing the totalPay method to a double and then put in a return statement, but that didn't work and now I don't know what to do (or even where I should start looking). . .
It's not ignoring those lines. What makes you think it is?
posted 8 years ago
Well, it doesn't display anything, which I guess it wouldn't, but I don't know how to get the program to display the heading and the subsequent employee information. I thought I could call getHeading and then getString, but nothing happens when I do that. Here's what I was hoping to get it to display:
Emp Num Employee Name Payrate HoursWorked Total Pay
191 John Doe 7.99 34.00 271.66
290 Jane Doe 9.99 44.00 439.56
I tried putting this at the end, but I think I still don't understand the correct syntax and where the items are supposed to be calling to:
When you say "I tried X but it didn't work," you need to be specific about what "didn't work" means. In this case, it's easy to see what you did wrong, but in the future, remember to provide details.
getHeading and toString are methods, so you need parentheses when calling them, that is, getHeading() and toString().
Additionally, calling println(X.toString()) is the same as just println(X), since println() ends up calling toString() anyway. The only difference is that println checks for null first and prints the string "null". If you just call toString() like you're doing, without checking for null, and it is null, you'll get a NullPointerException.
New rule: no elephants at the chess tournament. Tiny ads are still okay.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop