Question: Lab 3 address: https://www.chegg.com/homework-help/questions-and-answers/create-novel-class-private-instance-variables-constructor-parameters-accessor-methods-titl-q66858406?trackid=TmYmiK25 Re-do lab 3 but this time the following methods must throw the following Exceptions given the following conditions: Make sure your

Lab 3 address: https://www.chegg.com/homework-help/questions-and-answers/create-novel-class-private-instance-variables-constructor-parameters-accessor-methods-titl-q66858406?trackid=TmYmiK25

Re-do lab 3 but this time the following methods must throw the following Exceptions given the following conditions:

Make sure your methods declare the Exceptions they throw (and Javadoc @throws too). For example:

/**

* @param parameter - some parameter

@throws NullPointerException if parameter is null

@throws IllegalArgumentException if parameter is bigger than 100

*/

SAMPLE:

public void pretendMethod(String parameter) throws IllegalArgumentException, NullPointerException

{

// code goes here

}

printTitlesOfLength(int length)

Must throw an IllegalArgumentException if length is 0 or negative with the message bad length

printNameStartsEndsWith(String substring)

Must throw a checked Exception (YOU create the class) named IllegalNameException with the message "bad name" if the substring parameter is null or blank

printTitlesContaining(String substring, boolean caseSensitive)

Must throw a NullPointerException (with message null not allowed) if the substring parameter is null

Must throw an IllegalArgumentException (with message bad string) if the substring parameter is blank

NOTE: when a method or constructor throws one of several different methods, the try/catch block is extended as follows:

try

{

// code to try

}

catch(ExceptionTypeOne e)

{

// handle exception type one here

}

catch(ExceptionTypeTwo e)

{

// handle exception type two here

}

Etc

getLongest(String property)

Must throw an unchecked Exception (YOU create the class) named IllegalNovelPropertyException with the message "bad property" if its value is not "author" nor "title" (in any letter casing)

main(String[] args)

Must try/catch all of its methods now; in the event of an Exception being thrown, simply print the Exception objects getMessage() method output.

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 Databases Questions!