Computer Science Canada Java:: Output errors? |
Author: | antitru5t [ Tue Feb 17, 2009 10:11 pm ] | ||||||||
Post subject: | Java:: Output errors? | ||||||||
I am currently working on a JAVA Assignment and I am HAVING A TERRIBLY HARD TIME WORKING THROUGH IT. Please help me. ... Here are the business rules to my problem:: If the pay is from 0.00 to 399.99, the tax rate should be 7%. If the pay is from 400.00 to 899.99, the tax rate should be 11%. If the pay is from 900.00 and up, the tax rate shouldbe 15%. The proper output should be something like this when numbers are entered from the SCANNER:: Enter number of hours worked (0.00) <0 for Quick exit>: 39 Enter first number of hours straight (integer or 0 to disable): 40 Enter hourly rate of worker (00.00): 10 =================================================== Here is how my EXACT output should be like:: ================================================= Gross pay is: $390.00 Tax is : 7% Net pay is : $362.70 -------------------------------------------------------------- am not getting the correct output like this... Instead, I HAVE A HUGE, HECTIC PROBLEM that has startled me for hours. I am getting an output like this: Gross pay is: ($356.00) <----- These calculations are all WRONG. Tax Rate: 0.11 I can give you the whole code. Can you help me fix it? The main class ASSIGN2A.JAVA
CALPAYROLL.JAVA
PAY.JAVA
PAYROLL.JAVA
I need desperate help QUICKLY. . . =( .. I am so lost. - Nathe |
Author: | DemonWasp [ Tue Feb 17, 2009 10:49 pm ] | ||||
Post subject: | RE:Java:: Output errors? | ||||
First off, this appears to be wrong:
What you probably meant here is:
That way, it's all done with the same object. Perhaps worse, your definition of "calc_payroll()" appears to vary wildly. You need to decide EXACTLY what each method is going to take, and what it's going to return. In Payroll, calc_payroll returns the NET pay, but in Pay, it returns the GROSS pay. You may want to consider methods being named more descriptively: "getGrossPay" and "getNetPay" come to mind. Side notes (not to be insulting, just to make it easier for you to read your code and for us to help you): 1. Compsci.ca supports a nonstandard feature: syntax tags! Use [ syntax = " language " ] [ / syntax ] to highlight your code (minus all those spaces, and substituting your language of choice, of course). 2. You do not need to say super.methodName() to call methodName unless you're specifically calling a method in a superclass (that is, you've overridden methodName in this, but you want to call the one in super. 3. Java has a naming convention intended to make reading code easier. This convention is fairly simple. For classnames, each word starts with a capital: MyClassName. For variable names and method names, each word except the first starts with a capital: myClassInstance, myMethodName. Files are named exactly as the class in the file, with .java on the end. There's more to it, but that's the basics. |
Author: | OneOffDriveByPoster [ Tue Feb 17, 2009 11:16 pm ] |
Post subject: | Re: Java:: Output errors? |
I didn't look close enough to see if your code is otherwise correct, but I notice that you are doing calculations at (single) float precision. I would suggest replacing your floats with doubles. I personally would use BigInteger with scaled values, but I don't suppose that is necessary here. |
Author: | wtd [ Wed Feb 18, 2009 1:34 am ] |
Post subject: | RE:Java:: Output errors? |
You should be using floating point to deal with money at all. Has no one here seen Office Space? $1.25 is not a dollar and a quarter. It's exactly 125 pennies. |
Author: | DemonWasp [ Wed Feb 18, 2009 3:13 am ] |
Post subject: | RE:Java:: Output errors? |
Quote: Assignment
I figured that using floats was probably acceptable in this case. But yes, were this a financial application, BigInteger would be the correct choice. |