aspose file tools*
The moose likes Beginning Java and the fly likes Stuck on calc and return Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Stuck on calc and return" Watch "Stuck on calc and return" New topic
Author

Stuck on calc and return

Blue Zen
Greenhorn

Joined: Nov 12, 2011
Posts: 2
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). . .

Here's my class file:




And here's my driver file:




Thanks for looking at this!

Kindest regards,

S
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

It's not ignoring those lines. What makes you think it is?
Blue Zen
Greenhorn

Joined: Nov 12, 2011
Posts: 2
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:

System.out.println(Employee.getHeading);
System.out.println(empl1.toString);
System.out.println(empl2.toString);

Thanks! S
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Blue Zen wrote:Well, it doesn't display anything, which I guess it wouldn't,


Right. Because you're not telling it to. So we can dispense with that line of thinking.

but I don't know how to get the program to display


Yes, you do. I know this, because you're doing it elsewhere.

I thought I could call getHeading and then getString, but nothing happens when I do that.


Incorrect. Something happens. You seem to be back to assuming that every step that happens will automagically be printed out.

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:

System.out.println(Employee.getHeading);
System.out.println(empl1.toString);
System.out.println(empl2.toString);



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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Stuck on calc and return