Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: employe payroll

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry employe payroll

    getting error java.util.inputmismatchexception when i am entering employee full name.


    import java.util.*;
     
     
      class Demo
     
    {
     
          String id,name,address;
          double  bs,da,hra,pf,ts,as,gs,it;
     
       void Input()
     
      {
         Scanner s=new Scanner(System.in);
     
      System.out.println("EnterEmployee ID");
      id=s.next(); 
     
      System.out.println("Enter Employee Name"); 
      name=s.next();
     
      System.out.println("Enter Employee Address");
      address=s.next();
     
      System.out.println("Enter Employee Base Salary");
      bs=s.nextDouble();
     
      }
     
     
         void Ca()
      {
     
     
       da=.2*bs;
     
       hra=.1*bs; 
     
       pf=0.05*bs;
     
       ts=da+bs+hra-pf;
     
       as=ts*12;
     
       System.out.println("|================Employee Payroll ============== |");
     
       System.out.println("Employee ID          = "+id);
     
     
       System.out.println("Employee Name        = "+name);       
     
     
       System.out.println("Employee Address     = "+address);
     
     
       System.out.println("Employee Base Salary = "+bs); 
     
     
       System.out.println("|===============DA PF HRA  AND TOTAL SALARY AND TAXES  =========== |");
     
     
       System.out.println("DA            = "+da);
     
     
       System.out.println("HRA           = "+hra);
     
     
       System.out.println("PF            = " +pf);
     
     
       System.out.println("Total Salary  = "+ts);
     
     
       System.out.println("Annual Salary = "+as);
     
       if(as<180000)
     
      {
          System.out.println("No Tax");
          gs=as;
          System.out.println("Gross salary = "+gs);
     
      }
     
        else if(as>180000 && as<300000) 
      {
       System.out.println("10 percent of Annual Salary have to pay as Tax");
       it=.1*as;
       gs=as-it;
      System.out.println("Gross Salary    = "+gs);
      }
     
       else if(as>300000 && as<400000)
       {
        System.out.println("20 percent of Annual Salary have to pay as Tax");
        it=.2*as;
        gs=as-it;
       System.out.println("Gross Salary = "+gs);
        }
     
       else if(as>400000)
       {
        System.out.println("30 percent of Annual Salary have to pay as Tax");
       it=0.3*as;
       gs=as-it;
       System.out.println("Gross Salary    = "+gs);
     
       if (gs>=1000000)
       {
       System.out.println("  Grading   =    A GRADE");
        }
      }
     else
    {System.out.println("INVALID KEYWORD");
    }
     
     }
    }
    Last edited by jps; April 18th, 2013 at 02:01 PM. Reason: added code tags


  2. #2
    Junior Member
    Join Date
    Apr 2013
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: employe payroll

    next() family of functions read up to the next space. So if your full name is made up of first + last name, only the first will be read, last name remains in the buffer until the following next() call. What is probably happening is that nextDouble() reads a String and it does not like it...

    Word of advise, use code tage when submitting code. It makes it more inviting to people to help you.

  3. #3
    Junior Member
    Join Date
    Apr 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: employe payroll

    thanx

Similar Threads

  1. Payroll Program Only Returning Value Of 0
    By starterkit123 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 16th, 2013, 10:17 AM
  2. Trouble with Java payroll program
    By Shawn Wray in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 4th, 2012, 12:57 AM
  3. [SOLVED] Please help me with this payroll program
    By Leprechaun_hunter in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 14th, 2011, 06:47 PM
  4. heeeeeyyyy .. HELP ! :) -- PAYROLL SYSTEM --
    By princess in forum Java Theory & Questions
    Replies: 5
    Last Post: February 27th, 2011, 03:11 PM
  5. Payroll
    By Kesh486 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 6th, 2010, 06:48 PM