How frustrating are logic errors? The program compiles, but does not spit out the expected answers. I'm working on a simple payroll calculator for a Java class I'm taking, and instead of getting the numbers I'm expecting, I'm getting all zero's. We're covering if and switch statements right now, so that's what this project centers around. The output for grossPay and netPay are 0.0 and 0.0. Other than that everything works. I'm assuming my problem is in the if statements. Can anyone spot the logic errors?
Also, in the default constructor, how do I set the char to a default value, similiar to a null string?
Here's the class:
And here's the driver:
Greg Roberts<br />CIS Student<br />University of West Florida
I don't know if you have solved your problem or not, but I made one change and had your program running. The only thing I did was move the call to the grossPay() and netPay() methods inside the getGrossPay() and getNetPay() methods, respectively.
I think you logic issue is naming the the two methods as "calculateGrossPay" and "calculateNetPay".
Everything else seems to work.
Best of luck,
posted 15 years ago
Originally posted by Greg Roberts: What would you normally use in a default constructor for a char variable?
Since all instance fields are initialized by the JVM (chars get '\u0000'), I'd remove the initialization of it from the constructor.
Just to test, I added the following line to one of my classes:and it compiled fine using JDK 1.4.2_05. I have no idea why javac isn't liking it on your end.