Write a program for user defined exception that checks the internal and external marks if the internal marks are greater than 40 it raise the exception internal marks are exceed , if the external marks are greater than 60 exception is raised and display the message the external marks are exceed (BL-6)
Answers
Answer:
Write a program for user defined exception that checks the internal and external marks if the internal marks are greater than 40 it raise the exception internal marks are exceed , if the external marks are greater than 60 exception is raised and display the message the external marks are exceed (BL-6)
Explanation:
Write a program for user defined exception that checks the internal and external marks if the internal marks are greater than 40 it raise the exception internal marks are exceed , if the external marks are greater than 60 exception is raised and display the message the external marks are exceed (BL-6)
Answer:
ANSWER IS GIVEN DOWN AND EXPLAINED
Explanation:
import java.io.IOException;
import java.util.Scanner;
public class InternalMarks extends Exception {
public InternalMarks(String s) {
super(s);
}
}
public class ExternalMarks extends Exception {
public ExternalMarks(String s) {
super(s);
}
}
public class Main {
public static void main(String args[]) throws IOException
{
int x,y;
Scanner s = new Scanner(System.in);
System.out.println("Enter Internal Marks");
x=s.nextInt();
if(x>40)
{
try {
throw new InternalMarks("Internal Marks > 40");
} catch (InternalMarks e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else
{
System.out.println("Internal MARKS = "+ x);
}
System.out.println("Enter External Marks");
y=s.nextInt();
if(y>60)
{
try {
throw new InternalMarks("External Marks Exceeded");
} catch (InternalMarks e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else
{
System.out.println("External MARKS = "+ y);
}
}
}