Name:-Nagesh Parab Roll No.: - 07

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Name :- Nagesh Parab

Roll no.:- 07

package exceptions;
import java.util.Scanner;
class validation extends Exception
{
public validation(String str)
{
super(str);
}
}
public class Except
{
public static void validateAge(int age)throws validation
{
if(age<18)
{
throw new validation("Not Valid For Voting.");
}
else
{
System.out.println("You are Validate to Take Degree Education.");
}
}
public static void validateMarrige(int age)throws validation
{
System.out.println("Enter The Gender\n1-Male\n2-Female");
Scanner in=new scanner(System.in);
int gender=in.nextInt();
if((gender==1&&age<21)||(gender==2&&age<18))
{
throw new validation("Not Eligible To Marry.");
}
else
System.out.println("Eligible To Marry.");
}
}
Name :- Nagesh Parab
Roll no.:- 07

public static void main(String[] args)


{
Scanner input=new scanner(System.in);
System.out.println("Enter The Age : ");
int age=intput.nextInt();
System.out.println("Choose the option \n1-Voting\n2-Education\n3-Marriage");
int menu=intput.nextInt();
switch(menu)
{
case 1:
try
{ validateAge(age);}
catch(validation e)
{System.out.print(e.getMessage());}
break;
case 2:
try
{ validateEdu(age);}
catch(validation a)
{System.out.print(a.getMessage());}
break;
case 3:
try
{ validateMarrige(age);}
catch(validation v)
{System.out.print(v.getMessage());}
break;
default:
System.out.println("Enter The Valid Option.");
}
input.clase();
}
}
Name :- Nagesh Parab
Roll no.:- 07

You might also like