Write a class that accepts a user's hourly rate of pay and number of hours worked. Display the user's gross pay, the withholding tax (15% of gross pay) and the net pay, (gross pay - withholding)

I have my code below, but I'm lost. I dont know what I'm doing wrong, if anyone could help me out. I would be ever so greatful :)

import java.util.Scanner;

public class Payroll
{
	public static void main(String[] args)
	{
		int hours;
		int rate;
		int tax;
		int grosspay;
		int netpay;
		int fedtax;


		Scanner keyBoard = new Scanner(System.in);

		System.out.print("Enter hourly pay rate: ");
		rate = keyBoard.nextInt();


		System.out.print("Enter hours worked: ");
		hours = keyBoard.nextInt();


		System.out.println("You worked " + hours + "at $ + rate");

		System.out.println("Gross pay: + grosspay");
		grosspay = (hours * rate);

		System.out.println("Withholding tax: $ + withholdingtax");
		tax = .15;
		withholdingtax = (grosspay * tax);

		System.out.println("Net pay: + netpay");
		netpay = (grosspay - withholdingtax);


	}
}

Write a class that accepts a user's hourly rate of pay and number of hours worked. Display the user's gross pay, the withholding tax (15% of gross pay) and the net pay, (gross pay - withholding)

I have my code below, but I'm lost. I dont know what I'm doing wrong, if anyone could help me out. I would be ever so greatful :)

import java.util.Scanner;

public class Payroll
{
	public static void main(String[] args)
	{
		int hours;
		int rate;
		int tax;
		int grosspay;
		int netpay;
		int fedtax;


		Scanner keyBoard = new Scanner(System.in);

		System.out.print("Enter hourly pay rate: ");
		rate = keyBoard.nextInt();


		System.out.print("Enter hours worked: ");
		hours = keyBoard.nextInt();


		System.out.println("You worked " + hours + "at $ + rate");

		System.out.println("Gross pay: + grosspay");
		grosspay = (hours * rate);

		System.out.println("Withholding tax: $ + withholdingtax");
		tax = .15;
		withholdingtax = (grosspay * tax);

		System.out.println("Net pay: + netpay");
		netpay = (grosspay - withholdingtax);


	}
}

lets see first off i think here is a mistake:

System.out.println("You worked " + hours + "at $ + rate");

it should look like this in order to display the rate:

System.out.println("You worked " + hours + "at $" + rate);

Another 3 problems the one the same as the above is here:

System.out.println("Withholding tax: $ + withholdingtax");
		tax = .15;
		withholdingtax = (grosspay * tax);

not only is it not being displayed right but you are tryin to display it before initializing and also tax shouldnt be declared as an int but rather a double as it has decimal places it should be like this:

double tax = 0.15;
		double withholdingtax = (grosspay * tax);
System.out.println("Withholding tax: $"+ withholdingtax);

Fox those errors up and im sure it will get easier,the same errors apply for the netpay and grosspay, remember you will have to also declare all other variables that have operations done to them by the double 'tax' as doubles also i.e grosssalary,withholdingtax etc

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.