#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    1
    Rep Power
    0

    Can't Get This To Work


    The assignment is this:
    Write a class that accepts a userís hourly rate of pay and the 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 written the code to be this.

    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;
    double withholdingtax = (grosspay * tax);

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


    }
    }



    When I try to run it I get this.

    MacBook-Pro:desktop user$ javac -classpath . test.java
    test.java:3: class Payroll is public, should be declared in a file named Payroll.java
    public class Payroll
    ^
    test.java:31: possible loss of precision
    found : double
    required: int
    tax = .15;
    ^
    test.java:35: possible loss of precision
    found : double
    required: int
    netpay = (grosspay - withholdingtax);
    ^
    3 errors

    I have no idea what I am doing I appreciate any help I can get
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
    class Payroll is public, should be declared in a file named Payroll.java
    This error says what to do: rename the java file to have the same name as the public class it contains: Payroll.java

    The value: .15 is not an int value. It should be assigned to a double variable, not an int variable. The int value of .15 is 0. That is why the message says: loss of precision

IMN logo majestic logo threadwatch logo seochat tools logo