Question: Write an exception class that can be thrown when a negative whole number is passed to a method. / / Code NegativeNumberException class header. {

Write an exception class that can be thrown when a negative whole number is passed to a method.
//Code NegativeNumberException class header.
{
//Code no-arg constructor header.
{
//Send "Error - Negative number!" to superclass constructor. Disregard any line advances.
}//END No-Arg Constructor
//Code a constructor that accepts the number that caused the exception through n.
{
//Send "Error - Negative number:" plus the value in n to superclass constructor. Disregard any line advances.
}//END Overloaded Constructor
}//END CLASS NegativeNumberException
3. Write a statement that throws an instance of the exception class from #2 above. Use a variable argument such as n or number if using the overloaded constructor.
//Code the statement.
4. The instance method getValueFromFile is public and returns an int. It accepts no arguments. The method is capable of throwing a FileNotFoundException and an IOException in that order.
//Code the header for this method.
5. Write a block statement that calls the getValueFromFile method from #4 above. Be sure to handle all the exceptions that the method can throw.
//Header for block that executes the method call that can throw an error.
{
//Assign the method call to value which is already declared.
}//END
//Code block that catches files that are not found through e.
{
System.out.printf("%s%n",);//Code argument that calls the error message.
}//END
//Code block that catches input/output errors through e.
{
System.out.printf("%s%n",);//Code argument that calls the error message.
}//END

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!