Question by snape_fan_2005: What did I do wrong in my code?
I am taking a programming class called Programming With Java(or something like that). We are using a book called “Java Programming” By: Joyce Farrell. I spent hours yesterday working on my code and I can’t get it to run. I keep getting answers. We are currently on Chapter 5 of the book titled “Making Decisions” and have just learned about if/else statements. Here is what we have to do: Write an application that prompts an employee for an hourly pay rate and hours worked. Compute gross pay (hours times rate), witholding tax, and net pay (gross pay minus withholding tax). Withholding tax is computed as a percentage of gross pay based on the following:
Gross Pay ($ ) Withholding Percentage
Up to and including 300.00 10
300.01 and up 12

Save the file as

Here is my code:

import javax.swing.JOptionPane;
public class ComputeNet
public static void main (String[] args)

String hoursString, rateString;
double hoursWorked;
double grosspay;
double netpay;
double hourlypay;
double witholding;
hoursString = JOptionPane.showInputDialog(null,
“Enter amount of hours worked:”);
rateString = JOptionPane.showInputDialog(null,
“Enter hourly rate:”);
hoursWorked = Double.parseDouble(hoursString);
hourlypay = Double.parseDouble(rateString);

grosspay = hourlypay * hoursWorked;
System.out.println(“Gross pay is ” + grosspay);

if (grosspay >= 300.01)
witholding = .12
witholding = .10

grosspay – (witholding * grosspay);
“Your net pay would be: ” + netpay);


Best answer:

Answer by SeeYouLater_Zee
witholding = .12;
witholding = .10;

netpay = grosspay – (witholding * grosspay);

maybe even
“Your net pay would be: ” + netpay);

Give your answer to this question below!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.