Can someone help please 1 Define the exception class called

Can someone help please! 1. Define the exception class called TornadoException. The class should have two constructors including one default constructor. If the exception is thrown with the default constructor, the method getMessage should return

\"Tornado: Take cover immediately!\"

The other constructor has a single parameter, m, of int type. If the exception is thrown with this constructor, the getMessage should return

\"Tornado: m miles away; and approaching!\"

Write a Java program to test the class TornadoException

This is what I have so far but i\'m not sure what\'s wrong with it

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class TornadoException extends Exception
{

public TornadoException()
{
try {
}
catch(Exception e)
{
String err = getMessage();
}

{
try { }
catch(Exception m)
{
String err = getMessage(m);
}
}

public String getMessage()
{
return \"Tornado: Take cover immediately!\";
}

public String getMessage(int m)
{
return \"Tornado: \"+ m +\" miles away; and approaching!”;
}

Can someone help please! 1. Define the exception class called TornadoException. The class should have two constructors including one default constructor. If the exception is thrown with the default constructor, the method getMessage should return

\"Tornado: Take cover immediately!\"

The other constructor has a single parameter, m, of int type. If the exception is thrown with this constructor, the getMessage should return

\"Tornado: m miles away; and approaching!\"

Write a Java program to test the class TornadoException

This is what I have so far but i\'m not sure what\'s wrong with it

Solution

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class TornadoException extends Exception
{
public TornadoException()
{
try {}
catch(Exception e){
String err = getMessage();
}
try { }
catch(Exception m)
{
String err = getMessage(m);
}
}
public String getMessage(){
return \"Tornado: Take cover immediately!\";
}
public String getMessage(Exception m){
return \"Tornado: \"+ m +\" miles away; and approaching!\";
}
public static void main(String arg[])throws TornadoException{
TornadoException TE=new TornadoException();
TornadoException TE1=new TornadoException();
}
}

The errors in the program is the way the double quotations has kept in the last line.

and you haven\'t closed the main class. so i have rectifed both the errors. and pasted the code above.

And i also attached the main methid, so that it wll be executed. otherwise program will be just compiled, it cant be executed. So in the main program i have throwed the TornadoException so that both the constructors are invoked. If anything else is required to be done or printed, comment it

Can someone help please! 1. Define the exception class called TornadoException. The class should have two constructors including one default constructor. If the
Can someone help please! 1. Define the exception class called TornadoException. The class should have two constructors including one default constructor. If the

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site