3 Replies Latest reply: Sep 16, 2008 11:24 AM by 843810 RSS

    What am I doing wrong??

    843810
      import java.util.Scanner;
      public class Exercise2_11 {
      public static void main(String []args){
      Scanner input = new Scanner(System.in);

      System.out.println("Enter employee's name:");
      int employee = input.nextInt();

      System.out.println("Enter number of hours worked: ");
      int hours = input.nextInt();

      System.out.println("Enter hourly pay rate: ");
      int pay = input.nextInt();

      int gross_pay = pay * hours;

      System.out.println("Enter federal tax withholding rate: ");
      int fedtax = input.nextInt();
      int fedtaxr = fedtax * (20/100);

      System.out.println("Enter state tax withholding rate: ");
      int statetax = input.nextInt();

      int statetaxr = statetax * (20/100);

      int deductions = fedtaxr + statetaxr;

      int total_pay = gross_pay - deductions;

      System.out.println("Employee name: " + employee);

      System.out.println("Hours worked: " + hours);

      System.out.println(" Enter payrate: " + pay);

      System.out.println(" Enter gross pay: " + gross_pay);

      System.out.println(" Deductions: ");
      System.out.println("\t Federdal Withholding (20.0%): " + fedtaxr);
      System.out.println("\t State Withholding (9.0%)" + statetaxr);
      System.out.println("\t Total deductions:" +deductions);
      System.out.println("Total pay: "+total_pay);
      }
      }
        • 1. Re: What am I doing wrong??
          795410
          Hi,

          Please change the following line.
           String employee = input.next();
          Thanks
          • 2. Re: What am I doing wrong??
            843810
            Here is the fixed code with double instead of int, so you can add like 6.5 or 0.0034 for pay and tax.

            By the way, try not to cross post because the admin get really mad when people do that. You are new so i thought id let you know.

            _________________________________________________________
            import java.util.Scanner;
             
            public class Exercise2_11
            {
               public static void main(String[] args)
               {
                  Scanner input = new Scanner(System.in);
             
                  System.out.println("Enter employee's name:");
                  String employee = input.next();
             
                  System.out.println("Enter number of hours worked: ");
                  double  hours = input.nextDouble();
             
                  System.out.println("Enter hourly pay rate: ");
                  double  pay = input.nextDouble();
             
                  double  gross_pay = pay * hours;
             
                  System.out.println("Enter federal tax withholding rate: ");
                  double  fedtax = input.nextDouble();
                  double fedtaxr = fedtax * 0.20;
             
                  System.out.println("Enter state tax withholding rate: ");
                  double  statetax = input.nextDouble();
             
                  double statetaxr = statetax * 0.20;
             
                  double deductions = fedtaxr + statetaxr;
             
                  double total_pay = gross_pay - deductions;
             
                  System.out.println("Employee name: " + employee);
             
                  System.out.println("Hours worked: " + hours);
             
                  System.out.println(" Enter payrate: " + pay);
             
                  System.out.println(" Enter gross pay: " + gross_pay);
             
                  System.out.println(" Deductions: ");
                  System.out.println("\t Federdal Withholding (20.0%): " + fedtaxr);
                  System.out.println("\t State Withholding (9.0%)" + statetaxr);
                  System.out.println("\t Total deductions:" + deductions);
                  System.out.println("Total pay: " + total_pay);
               }
            }
            • 3. Re: What am I doing wrong??
              843810
              Cough People usually reward duke stars for answered questions.*Cough*