• 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:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Stuck on calc and return

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's not ignoring those lines. What makes you think it is?
 
Blue Zen
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic