Thursday, August 31, 2023

BCA and B.Sc Programs - Programming in Java Lab - Bharathiar University - Practical Program 3- Write a Java Program to create an Exception called PayOut of Bounds and throw the exception.

 

Bharathiar University

Programming Java Lab
Java Program 3
Write a Java Program to create an Exception called PayOut of Bounds and throw the exception.

Source Code
 
import java.util.*;
//user defined exception class for pay out of bounds Exception
class PayOutOfBoundsException extends Exception
 {
    //Constructor 
    public PayOutOfBoundsException(String s)
    {
       super(s); //calls Exception class Constructor
    }
}
//Main class for User defined Exception
public class Salary
{
    public static void main(String args[])
    {
    
    Scanner in =new Scanner(System.in);
    System.out.println("Enter Employee Salary: ");
    //Get Employee salary from User
    int esal=in.nextInt();
    try{
        //Check if employee salary not between 3000 and 10000 
        if(esal<3000 || esal>10000)
        {
    // throw pay out of bounds exception with a message
            throw new PayOutOfBoundsException("Salary must be 3000 to 10000");
        }
         //print employee salary if given salary is within bounds
        System.out.println("The given salary of Employee is "+esal);
    }
   //catch block for payoutof bounds exception
    catch(PayOutOfBoundsException e)
    {
//catch the exception and prints the error message
        System.out.println(e);
    }
}
}

Output:


Program 12 BCA Madras University BCA Object Oriented Programming using C++ Practical Madras University Program 12 Implement a telephone directory using files

  BCA Object Oriented Programming using C++ Practical Madras University  Program 12  Implement a telephone directory using files SOURCE CODE...