Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6060207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:47:57+00:00 2026-05-23T08:47:57+00:00

I have created a program to check for input range for integer variable paycategory

  • 0

I have created a program to check for input range for integer variable “paycategory” but when I want to check for inputmismatch errors as well. I tried it but its not working… I don’t want to change the data type to string because the paycategory is supposed to be integer. Please help how to fix this problem ?

import java.util.Scanner;
import java.util.*;
import java.text.*;
import java.lang.Object.*;

public class TestEmployeePayRoll {

     public static void main(String Args[])
     {
        String EmployeeID = null, FirstName = null, LastName = null, result;
        double HoursWorked;
        int PayCategory = 0, counter = 0;

      do
      {  
        Scanner input = new Scanner(System.in);

        try 
            {
            int flag = 1;
            String input1 ;
            System.out.println("Enter your Employee ID number: ");
            while(flag==1){

            EmployeeID = input.nextLine();

            if(EmployeeID.trim().length()>=5){
                    flag = 0;

                    System.out.println("Enter the First Name: ");
                    FirstName = input.nextLine();

                    System.out.println("Enter Last Name: "+ " ");
                    LastName = input.nextLine();

            }else
            System.out.print("EmployeeID must be exactly 5 digits long: \n Enter the Employee ID again: ");
            }

            }
            catch(Exception e)
            {
               System.out.println("Exception ");
            }

         try{


        do{
            System.out.println("Enter the Pay Category: "+ " ");
            PayCategory = input.nextInt();

        if(!(PayCategory >0 || PayCategory <5))throw new InputMismatchException();
        {
            System.out.println("Pay Category must be between 1 and 4");
        }
        }

        while(PayCategory < 1 || PayCategory > 4);
         }

         catch(InputMismatchException e)
         {
             System.out.println("PayCategory must be integers");

         } 
        do
        {
            System.out.println("Enter the number of hours worked: ");
            HoursWorked = input.nextDouble();
            Double hours = new Double(HoursWorked);
            if(hours.isNaN())
        {
            System.out.println("---Enter a valid hours value---");
        }

            else if(!(HoursWorked >1 || HoursWorked <80))
        {
            System.out.println("---Enter value between 1 and 80---");
        }
        }

        while(HoursWorked < 1 || HoursWorked > 80);

        EmployeePayRoll obj1 = new EmployeePayRoll(FirstName, LastName, EmployeeID, HoursWorked, PayCategory);

        DecimalFormat fmt = new DecimalFormat("###,##0.00");

        System.out.println("\n-----------------------------------------------------");
        System.out.println("\n The pay details for:" + obj1.getName() + "\t\t\t" + "ID:" + EmployeeID);
        System.out.println("\n-----------------------------------------------------");
        System.out.println("Pay Category: \t\t\t" + obj1.getPayCategory());
        System.out.println("Hours Worked: \t\t\t" + obj1.getHoursWorked());
        System.out.println("Pay Rate: \t\t\t" + obj1.getPayRate());
        System.out.println("Gross Pay:  \t\t\t" + "$"+fmt.format(obj1.getGrossPay()));
        System.out.println("Tax Payable:  \t\t\t" + "$"+fmt.format(obj1.getTaxPayable()));
        System.out.println("\t\t\t\t---------");
        System.out.println("Net Pay: \t\t\t" + "$" + fmt.format(obj1.getNetPay()));
        System.out.println("\n------------------------------------------------------");
        System.out.println();
        System.out.println("\n Process another employee? (Y/N)");
        result = input.next();

        }
            while (result.equals("Y")||result.equals("y"));

    }

 }

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:47:58+00:00Added an answer on May 23, 2026 at 8:47 am

    Your condition below can never be true, so the InputMismatchException will never be thrown.

    if(!(PayCategory >0 || PayCategory <5))
        throw new InputMismatchException();
    

    Correct your condition.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web service I'm trying to load test. I created a program
I want to create a C# program to provision Windows Mobile devices. I have
I have several scripts that take as input a directory name, and my program
I have a server program (works on all three major os systems), created in
I have a program that creates a Windows user account using the NetUserAdd() API
I have an AppleScript program which creates XML tags and elements within an Adobe
I have been tasked with creating a program what will create take files in
I have a problem with my WPF program. I'm trying to create an object
In a C# program, I have an abstract base class with a static Create
Have created a c++ implementation of the Hough transform for detecting lines in images.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.